繁体   English   中英

要求用户重复该程序

[英]ask user to repeat the program

如果用户选择 Y,我试图让程序重复,但如果用户选择 N,程序将显示课程的总费用。 我在这里使用 do...while 循环,我不知道为什么,当用户键入 Y 时,程序没有重复以及如何显示总费用。 这是我的编码,还没有完成

#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');
    
}

您忘记了scanf(" %c", join)中的地址运算符& a sensible compiler with appropriate options would have warned about that.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM