Thread: Math Quiz program

  1. #16
    Registered User
    Join Date
    Aug 2017
    Posts
    10
    but then it wont show wether it is correct answer or not
    Code:
    do
    	{
    		no1 = rand() % 50 + 1;
    		no2 = rand() % 50 + 1;
    		pcAns = no1 + no2;
    		printf("%d + %d = ", no1, no2);
    		scanf("%d", &userAns);
    		int scanStatus = scanf("%d", &userAns);
    
    
    		if (scanStatus == 1)
    		{
    			if (userAns == pcAns)
    			{
    				printf("Congratulation, your have entered the correct answer!!\n");
    				mark = mark + 10;
    			}
    			else
    			{
    				printf("Sorry the correct answer is %d \n", pcAns);
    			}
    		}
    		else if(scanStatus == 0)
    		{
    			int ch;
    			while ((ch = getchar()) != '\n' && ch != EOF);
    			printf("Please answer in digit form\n");
    		}
    		count++;
    	} while (count <= 10);
    here is the output
    Please enter 1, 2, 3 or 4
    1
    You have selected ADDITION
    Please select a level of difficulty: 1-Beginner, 2-Intermediate, or 3-Advance
    1
    ADDITION BEGINNER SELECTED
    Please answer the 10 quetions given
    1 + 34 = a
    Please answer in digit form
    38 + 13 = a
    Please answer in digit form
    30 + 41 = a
    Please answer in digit form
    41 + 13 = 54

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > but then it wont show wether it is correct answer or not
    So why can't you put
    printf("Sorry the correct answer is %d \n", pcAns);

    In place of,
    printf("Please answer in digit form\n");

    Like say
    printf("Sorry the correct answer is %d, Please answer in digit form\n", pcAns);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 25
    Last Post: 07-28-2017, 04:47 PM
  2. Replies: 0
    Last Post: 07-24-2017, 07:57 AM
  3. quiz program
    By lmanukyan in forum C Programming
    Replies: 6
    Last Post: 12-22-2015, 08:50 AM
  4. Math Quiz Program Help
    By HystericalFool in forum C Programming
    Replies: 5
    Last Post: 11-17-2014, 12:00 AM
  5. making a math quiz program
    By mackieinva in forum C Programming
    Replies: 10
    Last Post: 09-17-2007, 03:38 PM

Tags for this Thread