【发布时间】:2014-02-19 05:39:50
【问题描述】:
这是正在发生的事情:我给变量“pay”一个值。以 16 为例。我使用 printf 打印付款,我得到 16 回来。然后我再次打印它,得到 0。如果我第三次打印它,我又得到 16。
另外,无论我做什么,员工类型似乎总是为 0。
感谢任何帮助。谢谢!
#include<stdlib.h>
#include<stdio.h>
int main(void)
{
float pay;
int employees;
int type;
int hours;
int items;
int i;
int j;
printf("How many employees? ");
scanf("%d", &employees);
float array[employees][2];
for(i = 0; i < employees; i++)
{
printf("\nWhat type of employee is employee #%d?", i + 1);
printf("\nEnter \"1\" for Manager.\nEnter \"2\" for Hourly Worker.\nEnter \"3\" for Commission Worker.\nEnter \"4\" for Pieceworker.");
scanf("%d", &type);
switch (type)
{
case 1:
array[i][0] = 1;
printf("\nWhat is the weekly pay for employee #%d (manager)?", i + 1);
scanf("%f", &pay);
array[i][1] = pay;
printf("\nEmployee #%d earned $%.2f this week.", i + 1, array[i][1]);
break;
case 2:
array[i][0] = 2;
printf("\nWhat is the hourly pay for employee #%d (Hourly Worker)?", i + 1);
scanf("%f", &pay);
printf("\nHow many hours did employee #%d work this week?", i + 1);
scanf("%d", &hours);
if (hours > 40)
{
pay = ((hours - 40) * pay * 1.5) + (hours * pay);
}
else
pay *= hours;
array[i][1] = pay;
printf("\nEmployee #%d earned $%.2f this week.", i + 1, array[i][1]);
break;
case 3:
array[i][0] = 3;
printf("\nWhat were the gross sales for employee #%d (Commission Worker)?", i + 1);
scanf("%f", &pay);
pay = (pay *.057) + 250;
array[i][1] = pay;
printf("\nEmployee #%d earned $%.2f this week.", i + 1, array[i][1]);
break;
case 4:
array[i][0] = 4;
printf("\nHow many items did employee #%d (Pieceworker) produce this week?", i + 1);
scanf("%d", &items);
printf("\nHow much does employee #%d get paid for every item they produce?", i + 1);
scanf("%f", &pay);
pay *= items;
array[i][1] = pay;
printf("\nEmployee #%d earned $%.2f this week.", i + 1, array[i][1]);
break;
}
array[i][0] = type;
printf("\n\nEmployee type: %d", array[i][0]);
printf("\nEmployee #%d earned $%.2f this week.", i + 1, array[i][1]);
}
printf("\n\nEmployee # | Employee Type | Weekly Pay");
for(j = 0; j < employees; j++)
{
printf("\n%10d | %13d | $%.2f", j + 1, array[j][0], array[j][1]);
}
}
编辑:现在我可以打印付费的价值了。但是,当我尝试打印员工类型时,我仍然得到 0。
此外,打印图表的最后一个循环仍然在两个值上返回 0。有任何想法吗? (以上代码已更新)
【问题讨论】: