C code,我丢失了这个控制语句的程序? [英] C code, what am I missing for this control statement program?
问题描述
我工作的程序。这就是我试图来实现的;
该方案应present工资率的菜单,从中选择。使用一个开关来选择工资率。运行的开始应该是这个样子:
如果选择1到4选中,程序应要求工作时间。该方案应回收,直到输入5。如果超过1至5输入选择其他的东西,程序应该提醒用户什么样的正确选择是,然后回收。使用#define的常量的各种收益率和税率。
这是code我到目前为止,我错过什么;
的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;诠释的main()
{
INT的选择,每小时;
浮taxe,总;的printf(************ ***************** \\ n);
的printf(\\ n输入对应于希望工资率或采取行动的数目);
的printf(\\ N1)$ 8.75 /小时);
的printf(\\ N2)$ 9.33 /小时);
的printf(\\ N3)$ 10.00 /小时);
的printf(\\ N4)$ 11.20hr);
的printf(\\ N5)退出);
的printf(************ ***********的\\ n);scanf函数(%d个,&安培;选择);的printf(请输入小时数:);
scanf函数(%d个,&安培;小时);开关(选择){
情况1:
总= 8.75 *小时;
打破;
案例2:
总= 9.33 *小时;
打破;
案例3:
总= 10.00 *小时;
打破;
情况4:
总= 11.20 *小时;
打破;
情况5:
打破;
返回0;
}
}
我是什么失踪?
块引用>您错过了什么是真正的迭代。
程序应该循环,直到输入5。
块引用>这意味着你必须做一个循环,每次都会检查,如果读出的值是里面所有的工作
5
,你为了阻止迭代需要。您可以使用下列方式之一:
while循环:的
scanf函数(%d个,&安培;选择);
而(选择!= 5)
{
....
开关(选择){
....
}
....
scanf函数(%d个,&安培;选择);
}
的for循环:的
的(scanf函数(%d个,&安培;选择),选择= 5;!scanf函数(%d个,&安培;选择);)
{
....
开关(选择){
....
}
....
}
do-while循环:的
{做
scanf函数(%d个,&安培;选择);
....
开关(选择){
....
}
....
}而(选择= 5!);
I am working on a program. This is what I am attempting to achieve; The program should present a menu of pay rates from which to choose. Use a switch to select the pay rate. The beginning of a run should look something like this:
If choices 1 through 4 are selected, the program should request the hours worked. The program should recycle until 5 is entered. If something other than choices 1 through 5 is entered, the program should remind the user what the proper choices are and then recycle. Use #defined constants for the various earning rates and tax rates.
This is the code I have so far, what am I missing?;
#include <stdio.h> #include <stdlib.h> int main() { int choice, hour; float taxe, total; printf("****************************************************************\n"); printf("\nEnter the number corresponding to the desired pay rate or action"); printf("\n1)$8.75/hr"); printf("\n2)$9.33/hr"); printf("\n3)$10.00/hr"); printf("\n4)$11.20hr"); printf("\n5)Quit"); printf("**********************************************************\n"); scanf("%d", &choice); printf("Please enter number of hours: "); scanf("%d", &hour); switch(choice){ case 1: total = 8.75* hour; break; case 2: total = 9.33*hour; break; case 3: total = 10.00*hour; break; case 4: total = 11.20*hour; break; case 5: break; return 0; } }
解决方案what am I missing?
What you are missing is the actual iteration.
The program should recycle until 5 is entered.
This means that you have to do all your work inside a loop, which will check each time if the value read is
5
, which you need in order to stop iterating. You can use one of the following ways :
while loop:
scanf("%d", &choice); while (choice != 5) { .... switch(choice){ .... } .... scanf("%d", &choice); }
for loop:
for (scanf("%d", &choice); choice != 5; scanf("%d", &choice);) { .... switch(choice){ .... } .... }
do-while loop:
do{ scanf("%d", &choice); .... switch(choice){ .... } .... }while(choice != 5);
这篇关于C code,我丢失了这个控制语句的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!