Thread: Why this quiz game not working

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

    Unhappy Why this quiz game not working

    hello friends,

    I am trying to make a quiz game

    but after you press 'S" and register your name
    then when i press Y so that the quiz start its going back to main menu

    but when i press shift y in my keyboard the quiz starts
    but even though i select right answer it shows you are wrong?

    but when i select shift and the correct choice it works
    so somehow toupper() function not working ?

    here is my code just look into main function

    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;
        }
    
    
    
    
    
    
         }
    
    
    
    
         }
    
    
         if(count>=2){
    
    
            printf("\nyay you win");
         }else{
            printf("\nyou lost");
         }
        }
    
    
    
    
    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 CODEWITHC *********************************");
    }
    Last edited by sash_007; 07-05-2019 at 09:07 PM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,730
    Your toupper() calls are wrong. You needs to first call it for the character before you compare the character with the one you want, not after.

    What I'm saying is:
    Code:
    // Change this, and others like it...
    if(toupper(getch()=='D'))
    // To this:
    if(toupper(getch())=='D')
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Defenition Game not working with score
    By HelloDarkness in forum C Programming
    Replies: 1
    Last Post: 04-28-2016, 06:52 AM
  2. working on a little puzzle game.
    By metaldemon in forum Game Programming
    Replies: 2
    Last Post: 10-18-2011, 09:55 AM
  3. My Game isn't working...
    By kimset in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2007, 01:42 AM
  4. my game over function is not working
    By swgh in forum C++ Programming
    Replies: 6
    Last Post: 06-24-2005, 07:57 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