簡體   English   中英

如何修復C語言中無法訪問的代碼? 我無法打印用戶的輸入

[英]How to fix the unreachable code in C? I can't print the user's input

當我運行代碼時,它顯示了無法訪問的代碼。 它不會影響我要打印的內容。 但是我只是無法打印用戶的輸入。

我試圖定義CRT_SECURE_NO_WARNINGS也無濟於事

我希望打印出姓名,SID,凍結,應付總額,但沒有打印出任何東西。 它只會打印名稱,SID等,而不會打印輸入的用戶密鑰。

if(GDR==1 && type==3){
        room_rate=150;
        strcpy(r[i].block, "A3");
        printf("\nHow many weeks of room booking?\n");
        scanf("%i",&R_week);

        printf("\nName\t\t:");
        scanf("%s",r[i].name);
        printf("Student ID\t :");
        scanf("%s",r[i].SID);
        printf("Type\t\t  :%s\n",rm[i].type);
        r[i].room=r[i].room+1;
        A3_no=1+A3_no;

        printf("\nDo you want to change your room type?\n1 Yes\n2 No\n3 Main Menu\nPlease enter your option:");
        scanf("%i",&change);
        if(change==1){
            Room_Type();
            Details();
            goto start;}
        if(change==2){
Meal2:
            printf("\nDo you want to subscribe for Meal?\n1 Yes\n2 No\nPlease enter your option:");
            scanf("%i",&A1_Meal);
            if(A1_Meal==1){
                printf("\n\nSorry, this service is not available for subscription. Thank you.\n");
                goto Gym2;}
            if(A1_Meal ==2){
                goto Gym2;}
            else{
                goto Meal2;}

Gym2:
            printf("\nDo you want to subscribe for Gym?\n1 Yes\n2 No\nPlease enter your option:");
            scanf("%i",&A1_Gym);
            if(A1_Gym==1){
                printf("\nSorry, this service is not available for subscription. Thank you\n");
                goto Internet2;}
            if(A1_Gym==2){
                goto Internet2;}
            else{
                goto Gym2;}
Internet2:
            printf("\nDo you want to subscribe for Internet?\n1 Yes\n2 No\nPlease enter your option:");
            scanf("%i",&A1_Internet);
            if(A1_Internet==1){
                Internet_rate=15;
                printf("\nHow many weeks of subscription?\n");
                scanf("%i",&I_week);
                goto Laundry2;}
            if(A1_Internet==2){
                Internet_rate=15;
                I_week=0;
                goto Laundry2;}
            else{
                goto Internet2;}
Laundry2:
            printf("\nDo you want to subscribe for Laundry?\n1 Yes\n2 No\nPlease enter your option:");
            scanf("%i",&A1_Laundry);
            if(A1_Laundry==1){
                Laundry_rate=20;
                printf("\nHow many weeks of subscription?\n");
                scanf("%i",&L_week);

                room_total= room_rate * R_week;
                L_total = Laundry_rate * L_week;
                I_total = Internet_rate * I_week;
                r[i].total = room_total + I_total+L_total;
                printf("\n============== Payment Details ===============\n");
                printf("\nWeekly rate for the room\t: RM%i\n%i weeks of subscription\t\t: RM%i\nWeekly rate for the laundry\t: RM%i\n%i weeks of subscription\t\t: RM%i\nWeekly rate for the Internet\t: RM%i\n%i weeks of subscription\t\t: RM%i\n\nTotal amount payable is RM%i.\n",room_rate, R_week, room_total, Laundry_rate,L_week,L_total,Internet_rate,I_week,I_total,r[i].total);
                goto Pay;}
            if(A1_Laundry==2){
                Laundry_rate=20;
                L_week=0;
                room_total= room_rate * R_week;
                L_total = Laundry_rate * L_week;
                I_total = Internet_rate * I_week;
                r[i].total = room_total + I_total+L_total;
                printf("\n============== Payment Details ===============\n");
                printf("\nWeekly rate for the room\t: RM%i\n%i weeks of subscription\t\t: RM%i\nWeekly rate for the laundry\t: RM%i\n%i weeks of subscription\t\t: RM%i\nWeekly rate for the Internet\t: RM%i\n%i weeks of subscription\t\t: RM%i\n\nTotal amount payable is RM%i.\n",room_rate, R_week, room_total, Laundry_rate,L_week,L_total,Internet_rate,I_week,I_total,r[i].total);
                goto Pay;}
            else{
                goto Laundry2;}
Pay2:
            printf("==============================================\n");
            printf("\nDo you want to cancel booking or proceed to make payment?\n1 Make Payment\n2 Cancel Booking\nPlease enter your option:");
            scanf("%i",&cancel);
            if(cancel==1){
                printf("\nDo you want to make payment now or later by cash?\n1 Now\n2 Cash\nPlease enter your option:");
                scanf("%i",&pay);
                if(pay==1){
                    strcpy(r[i].PS, "Paid");
                    printf("\nPlease deposit your money in the slot provided.\nMaximum cash per deposit is 100 pieces of any combined denominations.\n");
                    printf("Thank you for your payment.\n\n");
                    goto Printing_2;
                    continue;}
                if(pay==2){
                    strcpy(r[i].PS, "Pending");
                    printf("Please proceed to counter 1. Payment must be made within 7 days. Thank you.\n\n");
                    goto Printing_2;}
                else{
                    goto Pay2;
                    break;}}
            if(cancel==2){
                goto Main_Menu;}
            else{
                goto Pay2;}
Printing_2:
            printf("\n============== Hosteler Details ===============\n");
            printf("Name\t\t: %s\nStudent ID\t: %s\nGender\t\t: %s\nBlock\t\t: %s\nRoom Number\t: %i\nType\t\t: %s\nTotal payable\t: RM%i\nPayment Status\t: %s",r[i].name,r[i].SID,rm[i].Gender,r[i].block,A3_no,rm[i].type,r[i].total,r[i].PS);
            printf("\n============================================\n");}

        if(change==3){
            goto Main_Menu;}
        else{
            goto Main_Menu;}}

Pay2無法訪問之后,編譯器對您的代碼是正確的,因為在上述if condition ,以上laundary2會以使您的代碼運行以pay或返回laundary2 if condition 無論如何,在您的代碼中均未達到Pay2 ,並且我還沒有看到任何調用跳轉到Pay2

您的代碼存在邏輯錯誤,因為我們不知道應用程序和完整代碼,因此我們無法進一步提供幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM