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

时间:2017-03-25 23:36:52

标签: c debugging emacs printf

我创建了一个计算每周工资的计划,加班费是每周工资的1.5。 这是我的代码:

documents

我在运行程序时遇到了这个错误,我对此感到困惑?

#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;
}

我意识到我做了一些愚蠢的事;如果有人能帮我意识到自己的错误,我会感激不尽。

1 个答案:

答案 0 :(得分:2)

  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);

你错过了 if in else:

  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);