Hi, Quiz C program
I'm a first year CS student, and we have our first assignment. We have to make a quiz with a menu that will keep re-displaying
1.
2. and so on. But i can't enter 2 without choosing 1 and i cant display 3 without choosing 1 and answering 2. I've written the whole code..but the validation is getting to me. I have no idea what to do..i have used if and while loops but i keep getting blocked out. If use characters like underscore the loop i use to redisplay the menu goes crazy..so i have to find a way to fix that/ but I'm not sure how to tell the scanf to display error if character is inputted. Also, I'm thinking of using char option..as you'll see in my source code..well i used that..but default: always exits out of the loop and i cant tell it to redisplay instead of exiting.
Please help and i hope u understand what i'm trying to say lol..
Oh and however this code is crap im proud of it..its the longest code i've ever written..so no plagiarism! I have till Nov. 19 so ur help will be appreciated as soon as possible thanks.
I found a way to get option 3 if u answered the question and ur in the main menu. Butif you haven't answered the questions, and u entered 3..the code isnt doing what i want it to do..This is the question: in case you don't understand
Assignment 1

Due Date: Thursday, 19th November, 2009

You are required to develop a program that will simulate a mathematics quiz game. The game will include various features, each of which must be incorporated into your program.

Your program should be menu-driven and must display a main menu when run. The menu should include the following options:

1. Enter the number of questions to be asked for this round of the quiz (maximum of 5 questions allowed).
2. Start quiz
3. Display the number of questions that were answered (i) correctly and (ii) incorrectly for this round.
4. Exit Program



Criteria to include:

(a) Your program should continually run and re-display the main menu after each option has completed, i.e. start over again. Only when the customer enters option 4 (i.e. Exit Program), should your program terminate.

(b) For option 2, your program should display a simple mathematical question and ask the user to enter the answer. After the user has entered their answer, your program should display the correct answer beside the user's answer. Your program should then ask the next question (if there are more to ask) and continue this sequence.

For example:

Question 1: 9 / 3 + 6 = ?
6
You entered: 6 - Wrong !! The correct answer: 9

(c) After the user selects option 2, then finishes the quiz and your program returns to the main menu, your program should not allow the user to select option 2 again until either option 3 or 4 is selected.

(d) Try to take account of input errors by the user and display appropriate error messages.
And this is my updated code. I tried char for the switches, but it exits the loop..
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
/*this code is for to ask a number of questions in a quiz contest re-displaying a menu */
main() 
{
    int i ;
    int one, two, three, four ;
    int answer1 = 2 ;
    int answer2 = 9 ;
    int answer3 = 24;
    int answer4 = 100;
    char yesno ;
    int num1 = 0;
    int option = 0 ;
    do
    {
              
                            printf("         \n   ") ;
                            printf("      ((----))\n") ;
                            printf("      <--<\\\\_//>->\n") ;
                            printf("           | |   \n") ;
                            printf("          (===)\n") ;
                            printf("\n") ;
                            printf("    QUIZZITCH  CUP\n") ;//This is just some drawing of the prize cup that the winner would have
    
            printf("\n") ;
        
    
        printf("1. Enter the number of questions to be asked for this round of the quiz\n") ; 
        printf("2. Start quiz\n") ;
        printf("3. Display the numbers of questions that were (i) correctly (ii) incorrectly\n") ;
        printf("4. Exit Program\n") ;
        scanf("%d", &option) ;//waits for an input for 1, 2, 3 or 4
     
        while(option != 1&&option!=4&&option!=3) //if option is not =1 it willforce user to enter1. but if user chooses 3..it would go to the other while loop//this enables it to display the results of option3 if variable num1 isn't empty. if it is empty and user chose 3..then menu would be redisplayed
        {
            printf("You must choose 1 before you can proceed to quiz\n") ;
            scanf("%d", &option) ;
            if(option==4)
            {
                return 0;
            }
            i++ ;
              
        }    

        while(option!=3)
        {
            if(option == 3 && num1 == 0)
            {   
                printf("You must choose 1 before you can proceed to menu\n") ;
                scanf("%d", &option) ;
            }
            else
            {
                    break ;
            }
                i++ ;
        }

       
        switch(option) //the switch option allows me to choose number of questions i want .
        {
            case 1:
            {
                
                printf("1. One question\n") ;
          
                printf("2. Two questions\n") ; 
            
                printf("3. Three questions\n") ;
           
                printf("4. Four questions\n") ; 
            
                scanf("%d", &num1) ; //this scanf to read in the option for the number questions to be answered
                while(num1 != 1 && num1 != 2&& num1 != 3 && num1 != 4)
                {
                    printf("You must choose from 1-4 before you can proceed to quiz\n") ;
                    scanf("%d", &num1) ;
                    i++ ;
                }
            }
            
            
            case 2: 
            {
                
                switch(num1)//start of option 2 using num1 as a variable of numbers of questions to be asked 
                {
                    case 1:
                    {
                        printf("What is 1+1: *\n") ;
                        scanf("%d", &one) ;//the answer is stored in a variable one, two, three, four, and matched with answer1-5. if it matches..then result is displayed
                        if(one == answer1)
                        {
                            printf("%d is Correct!\n",answer1) ;
                            
                        }
                        else
                        {
                            printf("Incorrect!Answer is: %d\n",answer1) ;
                            
                        }
                       
                        break;
                    }//end of case 1 of question 1 
                    
                    case 2:
                    {   
                        printf("1. what is 1+1: *\n") ;
                        scanf("%d", &one) ;
                        if(one == answer1) 
                        {
                            printf("Correct!\n") ;
                            
                        }
                        else 
                        {
                            printf("Incorrect! Answer is: %d\n", answer1) ;
                        }
            
                        printf("2. what is 3 * 3: *\n") ;
                        scanf("%d", &two) ;
                        if(two == answer2)
                        {
                            printf("Correct!\n") ;
                        }
                        else
                        {
                            printf("Incorrect! Answer is: %d\n", answer2) ;
                        }
                        break ;
                    }//end of question 2
                    //case 3
                    
                  
                    case 3:
                    { 
                          
                        printf("1. what is 1+1: *\n") ;
                        scanf("%d", &one) ;
                        if(one == answer1)
                        {
                           
                            printf("Correct!\n") ;
                        }
                        else
                        {
                            
                            printf("Incorrect! Answer is %d\n", answer1) ;
                        }
                
                        printf("2. what is 3 * 3: *\n") ;
                        scanf("%d", &two) ;
                   
                        if(two == answer2)
                        {
                          
                            printf("Correct!\n") ;
                        }
                        else
                        {
                           
                            printf("Incorrect! Answer is %d\n", answer2) ;
                        }
                        
                        printf("3. what is 4!: *\n") ;
                        scanf("%d", &three) ;
                        
                        if(three == answer3)
                        {
                            
                            printf("Correct!\n") ;
                        }
                        else
                        {
    
                            printf("Incorrect! Answer is %d\n",answer3) ;
                        }
                        
                        break ;
                    }
                    case 4:
                    {
                        printf("1. what is 1+1: *\n") ;
                        scanf("%d", &one) ;
                        if(one == answer1)
                        {
                            printf("Correct!\n") ;
                        }
                        else
                        {
                            printf("Incorrect! Answer is %d\n", answer1) ;//one
                        }
                        //two
                        printf("2. what is 3 * 3: * \n") ;
                        scanf("%d", &two) ;
                        if(two == answer2)
                        {
                            printf("Correct!\n") ;
                        }
                        else
                        {
                            printf("Incorrect! Answer is %d\n",answer2) ;
                        }
                        //two
                        printf("3. what is 4!: *\n") ;
                        scanf("%d", &three) ;
                        if(three ==answer3)
                        {
                            printf("Correct!\n") ;
                        }
                        else
                        {
                            printf("Incorrect! Answer is %d\n", answer3) ;
                        }
                        printf("4. what is 800/2*4: *\n") ;
                        scanf("%d", &four) ;
                    
                        if(four == answer4)
                        {
                            printf("Correct!\n") ;
                        }
                        else
                        {
                           printf("Incorrect! Answer is %d\n", answer4) ;
                        }
                        break ; 
                    }
                    
                }
               break ;
            }//end of case 2 of switch(option)
            
          
            case 3:                  //beginning of case 3. case 3 shows how many questions the user answer correctly
            {
                if(num1==1)
                {
                    //by checking the various possibilities the user could have answered the question
                    if(one==2)
                    {
                        printf("i. You got 1 Correct!\n") ;
                    }
                    else
                    {
                        printf("ii. You got 1 Incorrect!!\n") ;
                    }
                    break ; 
                }
                if(num1==2) 
                {
                    if(one == 2 && two == 9)
                    {
                        printf("i. You got 2 Correct!\n") ;
                        printf("ii. You got none Incorrect!!\n") ;
                    }
                    else if(one == 2 && two!= 9||one!=2 && two == 9)
                    {
                        printf("i. You got 1 Correct!\n") ;
                    }
                    else
                    {
                        printf("ii. You got Everything Incorrect!!\n") ;
                    }
                    break ;
                }
                          
                if(num1==3)
                {
                    if(one != 2 && two !=9 && three == 24||one != 2 && two == 9 && three != 24||one == 2 && two != 9 && three != 24)
                    {
                        printf("i. You got 1 Correct!\n") ;
                        printf("ii. You got 2 Incorrect!!\n") ;
                       
                    }
                   
                        
                    else if(one == 2 && two == 9 && three != 24||one != 2 && two == 9 && three == 24||one == 2 && two != 9 && three == 24)
                    {
                        printf("i. You got 2 Correct!\n") ;
                        printf("ii. You got 1 Incorrect!!\n") ;
                       
                    }
                  
                    else if(one==2 && two==9 && three==24)
                    {
                        printf("i. You got Everything Correct\n") ;
                    }
                    else
                    {
                        printf("i. You got Everything Incorrect!!\n") ;
                    }
                    
                }
                
                if(num1==4)
                {
                    if(one == 2 && two !=9 && three != 24 && four != 100||one != 2 && two == 9 && three != 24 && four != 100||one != 2 && two != 9 && three == 24 && four!= 100||one != 2 && two != 9 && three != 24 && four==100)
                    {
                        printf("i.  You got 1 correct!\n") ;
                        printf("ii. You got 3 incorrect!!\n") ;
                       
                    }
                    
                    else if(one != 2 && two != 9 && three == 24 && four == 100||one == 2 && two == 9 && three != 24 && four != 100|| one != 2 && two == 9 && three == 24 && four != 100|| one == 2 && two != 9 && three != 24 && four == 100)
                    {
                        printf("i. you got 2 correct\n") ;
                        printf("ii. you got 2 incorrect\n") ;
                        
                    }
                    else if(one != 2 && two == 9 && three == 24 && four == 100||one == 2 && two != 9 && three == 24 && four == 100||one == 2 && two == 9 && three != 24 && four== 100||one == 2 && two == 9 && three == 24 && four!= 100)
                    {
                        printf("i. You got 3 Correct!\n") ;
                        printf("ii. You got 1 Incorrect!!\n") ;
                     
                    }
                    else if(one == 2 && two == 9 && three == 24 && four == 100)
                    {
                        printf("i. You got everything Correct\n") ;
                       
                    }
                    else
                    {
                        printf("i. you got everything Incorrect\n") ;
                    }
                    break;
                }
                break ;
            }//end of switch(num1)
            
            case 4:
            { 
                printf("Are you sure you want to exit quiz?\n") ;
                printf("Y/N") ;
                printf("\n") ;
                scanf("%1s", &yesno) ;
                if(yesno== 'Y'|| yesno == 'y')
                {
                    exit(0) ;
                }
                clrscr() ;
                break ; /*user must input y to quit*/
            }
        
            default: 
            {
                printf("Can't you follow simple instructions?\n") ;
                
                break ; 
            }
             
        }
    }while(option==1 || option==2 ||option==3 || option == 4) ;
    
    getch() ;
}
No, if I choose 3 in main menu..it should have followed the code which is up..but it doesnt
and im still stuck with the problem of char.if u type in _ or = or any whitespace the loop goes infinite..please help
im pure nervous lol..ideas please!!