c - 如何确定 C 调试错误中的每周工资;

标签 c debugging emacs printf

<分区>

我正在创建一个计算周薪的程序,其中加类费是周薪的 1.5。 这是我的代码:

#include <stdio.h>

int main()
{

  double payrate;
  double hours;
  double weeklypay = hours * payrate;
  double overtimehours = hours - 40;
  double overtimepay = weeklypay * 1.5;
  double overtimesalary =  weeklypay + (overtimehours * overtimepay);

  printf("What is your standard hourly pay rate?\n");
  scanf("%d",&payrate);
  printf("How many hours do you work in a week?\n");
  scanf("%d",&hours);

  if (hours <= 40)
    printf("This means your weekly pay is %d . \n", weeklypay);

  else (hours > 40)
     printf("This means your weekly pay is %d . \n", overtimesalary);


  return 0;
}

我在运行我的程序时不断收到此错误,我完全不明白为什么?

 expected ‘;’ before ‘printf’

我意识到我在做一些愚蠢的事情;如果有人可以帮助我意识到我的错误,我将不胜感激。

最佳答案

  if (hours <= 40)
    printf("This means your weekly pay is %d . \n", weeklypay);

  else (hours > 40)
     printf("This means your weekly pay is %d . \n", overtimesalary);

你错过了 else 中的 if:

  if (hours <= 40)
    printf("This means your weekly pay is %d . \n", weeklypay);

  else if (hours > 40)
     printf("This means your weekly pay is %d . \n", overtimesalary);

或者在这种情况下,您可以将其删除:

  if (hours <= 40)
    printf("This means your weekly pay is %d . \n", weeklypay);

  else
     printf("This means your weekly pay is %d . \n", overtimesalary);

关于c - 如何确定 C 调试错误中的每周工资;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43023211/

相关文章:

sql - 使用 OCI、长 SQL 语句将非常大的整数数组插入 Oracle DB

ios - 当我尝试使用 userDefaults 保存到 ui 颜色时,Xcode 给我错误 : Fatal error: Unexpectedly found nil while unwrapping an Optional value

python - Windows 8 + Emacs 24.3 + emacs-for-python : Pymacs helper did not start within 30 seconds

c - 如何在C中的牛顿拉夫森法中检测循环

c - C中的网络; bind() 需要它的论点吗?

c - 检查索引是否为 "out of bounds"的最佳方法

ios - 当 react native 应用程序未在 ios 设备上启动时如何调试

visual-studio - 什么是 “Microsoft C++ Visual Runtime Library: Runtime error!”,如何捕获?

macos - 为什么在 iTerm2 中 OSX 上的 emacs 看不到 C-S-<up>?

emacs - 用换行符替换Emacs查询