[英]ask user to repeat the program
i am trying to make the program repeat if the user choose Y, but if the user choose N, the program will display the total fee of the course.如果用户选择 Y,我试图让程序重复,但如果用户选择 N,程序将显示课程的总费用。 i am using do...while loop here and i cant figure out why, when the user key in Y, the program didnt repeat and how to display the total fee.我在这里使用 do...while 循环,我不知道为什么,当用户键入 Y 时,程序没有重复以及如何显示总费用。 here is my coding, it's not done yet这是我的编码,还没有完成
#include<stdio.h>
#define A 100
#define B 100
#define C 120
#define D 120
#define E 130
int main()
{
int totalFee;
char code, join;
printf("\t\t Training Centre\n");
do
{
printf("\nEnter course code: ");
scanf(" %c", &code);
if(code == 'A')
{
printf("Course name: C for beginner\nFees: 100");
}
else if(code == 'B')
{
printf("Course name: C++ for beginner\nFees: 110");
}
else if(code == 'C')
{
printf("Course name: Java for beginner\nFees: 120");
}
else if(code == 'D')
{
printf("Course name: Phyton for beginner\nD\nFees: 130");
}
else
{
printf("Course name: PHP for beginner\nFees: 140");
}
printf("\n\nDo you want to join other class? (Enter Y for 'Yes' / N for 'N'): ");
scanf(" %c", join);
}
while (join == 'Y' || join == 'y');
}
You forgot the address operator &
in scanf(" %c", join)
;您忘记了scanf(" %c", join)
中的地址运算符&
; a sensible compiler with appropriate options would have warned about that. a sensible compiler with appropriate options would have warned about that.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.