简体   繁体   中英

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. 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. 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) ; a sensible compiler with appropriate options would have warned about that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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