Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何显示给定多个值的变量的最大值?(C)方案编制_C - Fatal编程技术网

如何显示给定多个值的变量的最大值?(C)方案编制

如何显示给定多个值的变量的最大值?(C)方案编制,c,C,我正在为我的C编程课做一个家庭作业,所以我不是在寻找直接的答案,而是在寻找说明或指导。我的代码非常简单,我们现在只使用了3周的C语言,所以我提前道歉。到目前为止,我们只讨论了条件、循环、计数器、多重选择的开关/中断/继续、逻辑运算符和读取字符,所以如果您提到其他内容,我可能不知道 7 #include <stdio.h> 8 #include <math.h> 9 10 int main(void) 11 { 12 13 /*Define variables

我正在为我的C编程课做一个家庭作业,所以我不是在寻找直接的答案,而是在寻找说明或指导。我的代码非常简单,我们现在只使用了3周的C语言,所以我提前道歉。到目前为止,我们只讨论了条件、循环、计数器、多重选择的开关/中断/继续、逻辑运算符和读取字符,所以如果您提到其他内容,我可能不知道

 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);
7#包括
8#包括
9
10内部主管道(无效)
11 {
12
13/*定义变量*/
14 int响应,btaxrate,taxrate;
15浮动收入、税额、净收入;
16
17
18/*如果用户愿意,启动dowhile循环以多次运行程序*/
19做{
20
21
22/*从用户处获取收入金额*/
23 printf(“输入年度收入:”);
24加元(“%f”和收入);
25/*通过while循环检查以确保其高于0*/
26(收入30)
37         {
38 printf(“基准税率无效,请再次输入税率:”);
39 scanf(“%d”和b税率);
40         }
41
42/*根据收入金额确定税率*/
43如果(收入>=0和收入<50000)
{
45税率=B税率;
46         }
47如果(收入>=50000和收入<100000)
48         {
49税率=B税率+10;
50         }
51如果(收入>=100000和收入<250000)
52         {
53税率=B税率+20;
54         }
55如果(收入>=250000和收入<500000)
56         {
57税率=B税率+25;
58         }
59如果(收入>=500000)
60         {
61税率=B税率+30;
62         }
63
64
65/*taxamount和netincome的公式*/
66税额=(浮动)(收入*税率)/(浮动)100;
67净收入=(浮动)收入-(浮动)税额;
68
69
70/*告诉他们的税率、纳税额以及税后净收入*/
71 printf(“您的税率为:%d%%”,税率);
72 printf(“\n您缴纳的税款为%.2f美元”,taxamount);
73 printf(“税后净收入为:$%.2f”,净收入);
74
75
76/*询问用户是否希望再次运行该程序,如果希望,则获取“是”的值*/
77 printf(“\n是否继续?(0:退出1:继续:)”;
78扫描频率(“%d”和响应);
79
80
81}/*结束do*/
82
83/*作为dowhile的一部分,查看程序是否再次运行*/
84,而响应=1;

我应该显示taxamount的最高值、最低值和平均值,这取决于用户重新运行程序的次数,然后打印。例如,如果他们运行了5次(按1继续),taxamount的值是15000、8000、20000、35000和100000,我该如何打印“100000为最高值,8000为最低值,平均值为35600”

您只需创建一个临时变量,在第一次迭代中保存
taxamount
的值,并在后续迭代中检查新值是否更大并相应更新


从这里,我想你可以猜出如何进行其余的计算。

你只需制作一个临时变量,在第一次迭代中,你将
taxamount的值保存在那里,然后在后续迭代中,你检查新值是否更大,并相应地更新它


从这里,我想你可以猜出如何进行其余的计算。

你只需制作一个临时变量,在第一次迭代中,你将
taxamount的值保存在那里,然后在后续迭代中,你检查新值是否更大,并相应地更新它


从这里,我想你可以猜出如何进行其余的计算。

你只需制作一个临时变量,在第一次迭代中,你将
taxamount的值保存在那里,然后在后续迭代中,你检查新值是否更大,并相应地更新它


从这里,我想你可以猜到如何做剩下的计算。

所有的
哈哈
LOL
部分是什么?这个程序中的所有注释都是多余的。它使文本不那么严肃,如果你不喜欢,就不要读。是的,我知道,它们是非常多余的。我所在的班级需要它们。@Nick:首先所有人:这是一个严肃的平台,所以如果你不喜欢它,就不要在上面发表文章。这门课要求什么?它要求你做多余的评论?或者它要求你做评论?第一个在我看来像是一个奇怪的要求。第二个是一个很好的要求,但它是为了避免做多余的评论(这是很重要的)所有的
haha
LOL
部分有什么用?这个程序中的所有注释都是多余的。如果你不喜欢,就不要读。是的,我知道,它们是多余的。我所在的班级需要它们。@Nick:首先:这是一个严肃的平台,所以如果你不喜欢,就不要在上面发布。还有这门课要求什么?它要求你做多余的评论?或者它要求你做评论?在我看来,第一个要求很奇怪。第二个要求很好,但接下来就是避免做多余的评论(这根本不重要)所有的
haha
LOL
部分有什么用?这个程序中的所有注释都是多余的。如果你不喜欢,就不要读。是的,我知道,它们是多余的。我所在的班级需要它们。@Nick:首先:这是一个严肃的平台,所以如果你不喜欢,就不要在上面发布。还有这门课要求什么?它要求你做多余的评论?或者它要求你做评论?第一个在我看来是一个奇怪的要求。第二个是一个很好的要求,但是它是为了避免做多余的评论(这是很重要的)什么