我有以下程序:
#include <stdio.h>
int main (void)
{
int n, number, employeeNumber,counter;
float wage,hours,grossPay;
grossPay = wage*hours;
for ( counter = 1; counter <=5; ++counter) {
printf ("Enter Clock#:");
scanf ("%i",&number);
printf ("Enter Wage:");
scanf ("%f",&wage);
printf ("Enter Hours:");
scanf ("%f",&hours);
employeeNumber = 0;
for ( n = 1; n <= number; ++n)
employeeNumber +=n;
printf ("--------------------------------\n");
printf ("Clock# Wage Hours Gross\n");
printf ("--------------------------------\n");
printf ("%06i %.02f %.01f %f\n\n", number, wage, hours,grossPay);
}
return 0;
}
当我运行这个程序时,grossPay目前为零。我希望格罗斯比的工资*小时数相等,这将取决于我输入的工资和时钟号码的小时数。有谁能提供一个如何解决这个问题的提示吗?谢谢!
最佳答案
移动这条线
grossPay = wage*hours;
之后
scanf ("%f",&hours);
您应该在用户输入
grossPay
&wage
之后尝试计算hours
。默认情况下,在声明期间wage
和hours
将初始化为默认值,即0.0
,因此您将得到grossPay
零。关于c - C:将两个ScanF相乘,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14721933/