簡體   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