Thread: Issues with quiz game

  1. #1
    Registered User
    Join Date
    May 2019
    Posts
    40

    Exclamation Issues with quiz game

    hello friends,

    I am facing some issues with this quiz game

    after you press start and then y and pass the first round of questions

    it comes down to second challenge round of questions where if you answer 10 question correctly in one go then
    a message should show "you become a millionaire"
    however if you dont answer any question a message shows" sorry you dint win any cash"
    in my case if i answer 10 questions correctly in challenger round
    i dont see message "you become a millionaire" but however if i fail to answer any question in challenger round i see this message " sorry you dint win any cash"

    also when from main menu i press "V' registered name should show along with the amount of money won but it shows no name and just shows ____ has scored the highest score 0.00


    here is my code
    Code:
    #include <stdio.h>#include<conio.h>
    #include<ctype.h>
    #include <stdlib.h>
    #include<string.h>
    
    
    void show_record();
    void reset_score();
    void help();
    int main(){
    int countr,r,rl,count,i,n;
    float score;
    char choice;
    char playername[20];
    mainhome:
        system("cls");
        printf("\t\t\tC PROGRAM QUIZ GAME\n");
        printf("\n\t\t_____________________________________________");
    
    
        printf("\n\t\t\t      WELCOME  ");
        printf("\n\t\t\t        to  ");
        printf("\n\t\t\t     THE GAME  ");
        printf("\n\t\t_____________________________________________");
        printf("\n\t\t_____________________________________________");
        printf("\n\t\t   BECOME A MILLIONAIRE!!!!!!!!!!!     ");
        printf("\n\t\t_____________________________________________");
        printf("\n\t\t_____________________________________________");
    
    
        printf("\n\t\t > Press S to start the game ");
        printf("\n\t\t > Press V to view the highest score ");
        printf("\n\t\t > Press R to reset score ");
        printf("\n\t\t > Press H for help ");
        printf("\n\t\t > Press Q to quit ");
        printf("\n\t\t_____________________________________________");
        choice = toupper(getch());
    
    
        if (choice=='V'){
            show_record();
            goto mainhome;
        }else if (choice=='H') {
    
    
        help();
        getch();
        goto mainhome;
        } else if(choice=='R'){
    
    
        reset_score();
        getch();
        goto mainhome;
        }else if(choice == 'Q'){
    
    
        exit(1);
        }else if(choice =='S'){
    
    
        system("cls");
        printf("\n\n\n\n\n\n\n\n\t\t\tRegister your name:");
        gets(playername);
        system("cls");
        printf("\n---------------------Welcome %s to C Quiz Game-----------------------------",playername);
        printf("\n\n\t\tHere are some tips you might wanna know before playing:");
        printf("  -------------------------------------------------------------------");
        printf("\n\n >> There are two rounds in this Quiz game,WARMUP ROUND & CHALLENGE ROUND");
        printf("\n\n >> In Warm up Round  you will be asked total 3 questions to test your");
        printf("\n general knowledge.You are eligible to play the game if  you give at least 2");
        printf("\n right answers ,otherwise you can't proceed further to the Challenge round");
        printf("\n\n >> Your game starts at Challenge Round .In this round you will be asked a");
        printf("\n total of 10 questions,Each right answer will be awarded $100,000!");
        printf("\n By this way you can win up to ONE MILLION CASH PRIZE !!!!!.........");
        printf("\n\n >> You will be given 4 options and you have to press A , B ,C or D for the");
        printf("\n right option.");
        printf("\n\n >> You will be asked questions continuously till right answers are given");
        printf("\n\n >> No negative marking for wrong answers");
        printf("\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!ALL THE BEST  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
        printf("\n\n\n Press Y to start new game!\n");
        printf("\n Press any other key to return to the main menu");
        if(toupper(getch())=='Y'){
    
    
            goto home;
        }else{
    
    
         goto mainhome;
         system("cls");
        }
         home:
         system("cls");
         count = 0;
         for(i=0;i<=3;i++){
         system("cls");
         rl = i;
    
    
         switch(rl){
       case 1:
        printf("\n\nWhich of the following is Palindrome number?");
        printf("\n\nA.42042\t\tB.101010\n\nC.23232\t\tD.01234");
        if(toupper(getch())=='C'){
    
    
           printf("\nCorrect!!!");
           count++;
           getch();
           break;
    
    
        } else {
    
    
          printf("\nWrong!!! .The correct answer is C.23232");
          getch();
          break;
        }
    
    
         case 2:
        printf("\n\nThe Country with highest environmental performance index is...?");
        printf("\n\nA.France\t\tB.Denmark\n\nC.Switzerland\t\tD.Finland");
        if(toupper(getch())=='C'){
    
    
           printf("\nCorrect!!!");
           count++;
           getch();
           break;
    
    
        } else {
    
    
          printf("\nWrong!!! .The correct answer is C.Switzerland");
          getch();
          break;
        }
    
    
         case 3:
        printf("\n\nWhich animal laughs like human being?");
        printf("\n\nA.Polar Bear\t\tB.Hyena\n\nC.Donkey\t\tD.Chimpanzee");
        if(toupper(getch())=='B'){
    
    
           printf("\nCorrect!!!");
           count++;
           getch();
           break;
    
    
        } else {
    
    
          printf("\nWrong!!! .The correct answer is B.Hyena");
          getch();
          break;
        }
    
    
    
    
        case 4:
        printf("\n\nWho was awarded the youngest player award in Fifa World Cup 2006?");
        printf("\n\nA.Wayne Rooney\t\tB.Lucas Podolski\n\nC.Lionel Messi\t\tD.Christiano Ronaldo");
        if(toupper(getch())=='B'){
    
    
           printf("\nCorrect!!!");
           count++;
           getch();
           break;
    
    
        } else {
    
    
          printf("\nWrong!!! .The correct answer is B.Lucas Podolski");
          getch();
          break;
        }
    
    
    
    
        case 5:
        printf("\n\nWhich is the third highest mountain in the world?");
        printf("\n\nA.Mt. K2\t\tB.Mt. Kanchanjungha\n\nC.Mt. Makalu\t\tD.Mt. Kilimanjaro");
        if(toupper(getch())=='B'){
    
    
           printf("\nCorrect!!!");
           count++;
           getch();
           break;
    
    
        } else {
    
    
          printf("\nWrong!!! .The correct answer is B.Mt. Kanchanjungha");
          getch();
          break;
        }
    
    
    
    
        case 6:
        printf("\n\nWhat is the group of frogs known as?");
        printf("\n\nA.A Traffic\t\tB.A Toddler\n\nC.A Police\t\tD.An Army");
        if(toupper(getch())=='D'){
    
    
           printf("\nCorrect!!!");
           count++;
           getch();
           break;
    
    
        } else {
    
    
          printf("\nWrong!!! .The correct answer is D.An Army");
          getch();
          break;
        }
    
    
    
    
    
    
         }//switch end
    
    
    
    
         }//for loop end
    
    
         if(count>=2){
    
    
            goto test;
         }else{
    
    
            system("cls");
            printf("\n\nSORRY YOU ARE NOT ELIGIBLE TO PLAY THIS GAME, BETTER LUCK NEXT TIME");
            getch();
            goto mainhome;
         }
         test:
             system("cls");
             printf("\n\n\t*** CONGRATULATION %s you are eligible to play the Game ***",playername);
             printf("\n\n\n\n\t!Press Any Key to Start the Game!");
             if(toupper(getch())=='p'){
    
    
                goto game;
             }
             game:
             countr = 0;
             for(i=0;i<=10;i++){
    
    
               system("cls");
               r=i;
    
    
               switch(r){
    
    
            case 1 :
                printf("\n\nWhat is the national game of England?");
                printf("\n\nA.Football\t\tB.Basketball\n\nC.Cricket\t\tD.Baseball");
                if(toupper(getch())=='C'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is C.Cricket");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
                case 2 :
                printf("\n\nStudy of Earthquake is called.............,");
                printf("\n\nA.Seismology\t\tB.Cosmology\n\nC.Orology\t\tD.Etimology");
                if(toupper(getch())=='A'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is A.Seismology");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                 case 3 :
                printf("\n\nAmong the top 10 highest peak in the world,how many lie in Nepal?");
                printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.9");
                if(toupper(getch())=='C'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is C.8");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
    
    
                 case 4 :
                printf("\n\nThe Laws of Electromagnetic induction were given by?");
                printf("\n\nA.Faraday\t\tB.Tesla\n\nC.Maxwell\t\tD.Coulomb");
                if(toupper(getch())=='A'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is A.Faraday");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                case 5 :
                printf("\n\nWhat unit is electric power measured?");
                printf("\n\nA.Coulomb\t\tB.Watt\n\nC.Power\t\tD.Units");
                if(toupper(getch())=='B'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is B.Watt");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                case 6 :
                printf("\n\nWhich element is found in vitamin B12?");
                printf("\n\nA.Zinc\t\tB.Cobalt\n\nC.Calcium\t\tD.Iron");
                if(toupper(getch())=='B'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is B.Cobalt");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
    
    
                case 7 :
                printf("\n\nWhat is the national name of Japan?");
                printf("\n\nA.Polska\t\tB.Hellas\n\nC.Drukyul\t\tD.Nippon");
                if(toupper(getch())=='D'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is D.Nippon");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                case 8 :
                printf("\n\nHow many times a piece of paper can be folded at the most?");
                printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.Depends on the size of paper");
                if(toupper(getch())=='B'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is B.7");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                case 9 :
                printf("\n\nWhat is the capital of Denmark?");
                printf("\n\nA.Copenhagen\t\tB.Helsinki\n\nC.Ajax\t\tD.Galatasaray");
                if(toupper(getch())=='A'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is A.Copenhagen");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
    
    
                case 10 :
                printf("\n\nWhich is the longest river in the world?");
                printf("\n\nA.Nile\t\tB.Koshi\n\nC.Ganga\t\tD.Amazon");
                if(toupper(getch())=='A'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is A.Nile");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                case 11 :
                printf("\n\nWhat is the color of blackbox in aeroplanes?");
                printf("\n\nA.White\t\tB.Black\n\nC.Orange\t\tD.Red");
                if(toupper(getch())=='C'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is C.Orange");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
    
    
                case 12 :
                printf("\n\nWhich city is known as 'The City of Seven Hills'?");
                printf("\n\nA.Rome\t\tB.Vatican City\n\nC.Madrid\t\tD.Berlin");
                if(toupper(getch())=='A'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is A.Rome");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                case 13 :
                printf("\n\nName the country where no mosquitoes are found?");
                printf("\n\nA.Japan\t\tB.Italy\n\nC.Argentina\t\tD.France");
                if(toupper(getch())=='D'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is D.France");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
    
    
                case 14 :
                printf("\n\nWho is the author of Pulpasa Cafe?");
                printf("\n\nA.Narayan Wagle\t\tB.Lal Gopal Subedi\n\nC.B.P.Koirala\t\tD.Khagendra Sangraula");
                if(toupper(getch())=='A'){
    
    
                    printf("\n\nCorrect!!!");
                    countr++;
                    getch();
                    break;
                }else{
    
    
                   printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");
                   getch();
                   goto score;
                   break;
                }//case block
    
    
    
    
                score:
                    system("cls");
                    score =(float)countr*100000;
                    if(score>0.00 && score<1000000){
    
    
                        printf("\n\n\t\t******************CONGRATULATION*****************************");
                        printf("\n\tYou Won $%.2f",score);
                        goto go;
                    }else if(score ==1000000.00){
    
    
                         printf("\n\n\t\t******************CONGRATULATION*****************************");
                         printf("\n\t\t\t\tYOU ARE A MILLIONAIRE!!!!!!!!!");
                         printf("\n\tYou Won $%.2f",score);
                         printf("\t\tThank You!!!!");
    
    
    
    
                    }else{
    
    
                        printf("\n\n\t************SORRY YOU DIDN'T WIN ANY CASH********************");
                        printf("\n\t\tThanks for your participation");
                        printf("\n\t\t TRY AGAIN");
                        goto go;
    
    
    
    
                    }
    
    
                    go:
                        printf("\n\nPress Y if you want to play next game");
                        printf("\nPress any key if you want to go to main menu");
                        if(toupper(getch())=='Y'){
    
    
                            goto home;
                        }else{
                         printf("hey dude");
                         goto mainhome;
                        }
    
    
    
    
               }//switch statement end
    
    
             }//for loop end
        }
    
    
    
    
    return 0;
    
    
    }
    
    
    void show_record(){
    system("cls");
    char name[20];
    float scr;
    FILE *f;
    f = fopen("score.txt","r");
    fscanf(f,"%s%f",&name,&scr);
    printf("\n\n\n\t***********************************************************");
    printf("\n\n\n\t %s has scored the Highest Score %0.2f",name,scr);
    printf("\n\n\n\t***********************************************************");
    fclose(f);
    getch();
    
    
    }
    
    
    void reset_score(){
    system("cls");
    float sc;
    char nm[20];
    FILE *f;
    fopen("score.txt","r+");
    fscanf(f,"%s%f",&nm,&sc);
    sc = 0;
    fprintf(f,"%s%,.2f",nm,sc);
    fclose(f);
    
    
    }
    
    
    void help(){
    system("cls");
    printf("\n\n                                   HELP");
    printf("\n------------------------------------------------------------------------------------");
    printf("\n..............................C Program Quiz Game.......................");
    printf("\n  >>    There are two rounds in the game, WARMUP ROUND & CHALLENGE ROUND");
    printf("\n  >>    In warmup round you will be asked 3 questions to test your general");
    printf("\n        knowledge .You will be eligible to play the game if you give at least 2");
    printf("\n        right answers otherwise you can't play the Game................");
    printf("\n  >>    Your game starts with the CHALLENGE ROUND. In this round you will be asked");
    printf("\n        total 10 questions ,each right answer will be awarded $100,000.");
    printf("\n        By this way you win up to 1million cash prize in USD.................");
    printf("\n  >>    You will be given 4 options and you have to press A ,B ,C or D for the");
    printf("\n        right option.");
    printf("\n  >>    You will be asked questions continuously if you keep giving the right answers");
    printf("\n  >>    No negative marking for wrong answers");
    
    
    printf("\n\n\t*****************************BEST OF LUCK****************************************");
    printf("\n\n\t******************C PROGRAM DEVELOPED BY ****************************************");
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,688
    I suggest the use of more functions. And, stop using goto till you learn more about programming.
    And, learn to indent your code.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User catacombs's Avatar
    Join Date
    May 2019
    Location
    /home/
    Posts
    72
    Surely there must be a way to load the questions from another file, yes?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why this quiz game not working
    By sash_007 in forum C Programming
    Replies: 1
    Last Post: 07-05-2019, 09:06 PM
  2. Animation issues with my 2d game?
    By Tyler Dahle in forum C Programming
    Replies: 8
    Last Post: 04-10-2013, 12:27 PM
  3. Functino Issues Ending Game
    By StoryGame464 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2009, 06:06 PM
  4. Major game issues
    By VOX in forum Game Programming
    Replies: 0
    Last Post: 01-18-2005, 08:40 AM
  5. Text-based quiz game
    By MipZhaP in forum Game Programming
    Replies: 7
    Last Post: 09-09-2004, 02:33 PM

Tags for this Thread