我正在为我的C编程班做一个家庭作业,所以我不是在寻找直接的答案,而是寻求指导或指导。我的代码非常简单,我们现在只使用C 3周,所以我提前道歉。到目前为止,我们只覆盖了条件,循环,计数器,多个选择的切换/中断/继续,逻辑运算符和读取字符,所以如果你提到的不是这个,我可能会毫无头绪。
7 #include <stdio.h>
8 #include <math.h>
9
10 int main(void)
11 {
12
13 /*Define variables*/
14 int response, btaxrate, taxrate;
15 float income,taxamount, netincome;
16
17
18 /* Start the dowhile loop for running the program more than once if the user wants to */
19 do{
20
21
22 /*Grab the income amount from the user */
23 printf("Enter the annual income: ");
24 scanf("%f", &income);
25 /* Check to make sure it is above 0 with a while loop */
26 while(income <= 0)
27 {
28 printf("Invalid income, enter the income again: ");
29 scanf("%f", &income);
30 }
31
32 /* Grab the base taxrate from the user */
33 printf("Enter the base tax rate: ");
34 scanf("%d", &btaxrate);
35 /* Check to make sure it is <10 or >30 with a while loop */
36 while(btaxrate < 10 || btaxrate > 30)
37 {
38 printf("Invalid base tax rate, enter the tax rate again: ");
39 scanf("%d", &btaxrate);
40 }
41
42 /* Determine what the taxrate is based on the income amount */
43 if(income >= 0 && income < 50000)
{
45 taxrate=btaxrate;
46 }
47 if(income >= 50000 && income < 100000)
48 {
49 taxrate=btaxrate+10;
50 }
51 if(income >= 100000 && income < 250000)
52 {
53 taxrate=btaxrate+20;
54 }
55 if(income >= 250000 && income < 500000)
56 {
57 taxrate=btaxrate+25;
58 }
59 if (income >= 500000)
60 {
61 taxrate=btaxrate+30;
62 }
63
64
65 /* Equations for taxamount and netincome */
66 taxamount=(float)(income*taxrate)/(float)100;
67 netincome=(float)income-(float)taxamount;
68
69
70 /* Tell them their tax rate, how much they pay in taxes, and their net income after taxes*/
71 printf("Your tax rate is: %d%%", taxrate);
72 printf("\nYou pay $%.2f in taxes.", taxamount);
73 printf("\nAfter taxes your net income is: $%.2f", netincome);
74
75
76 /* Ask the user if they want to run the program again, get a value for yes if so */
77 printf("\nDo you want to continue? (0:Exit 1:Continue:)");
78 scanf("%d", &response);
79
80
81 } /* End do */
82
83 /* While part of dowhile to see if the program runs again */
84 while(response == 1);
我应该显示根据用户重新运行程序的次数确定的最高值,最低值和平均税额,然后打印它。因此,例如,如果他们运行5次(通过按1继续)并且taxamount的值为15000,8000,20000,35000和100000,我将如何打印“100000是最高的,8000是最低的,而平均值是35600“?
答案 0 :(得分:3)
您可以创建一个临时变量,在第一次迭代中保存taxamount
的值,并在连续迭代中检查新值是否更大并相应地更新它。
从那里我想你可以猜测如何进行其余的计算。