Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried using
C#
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
    char a,b;
    int x=1,correct=0,incorrect=0,unattempted=0;
    printf("Enter Answer for Q.%d: ",x);
    scanf("%c",&a);
    x++;

    switch(a)
    {
    case 'A':
        printf("Correct \n");
        correct++;
        break;
    case 'U':
        unattempted++;
        break;
    default:
        printf("Wrong \n");
        incorrect++;
        break;
    }
    printf("Enter Answer for Q.2:");
    scanf("%c",&b);
    x++;
    switch(b)
    {
    case 'A':
        printf("Correct \n");
        correct++;
        break;
    default:
        printf("Wrong \n");
        incorrect++;
        break;
    }
    printf("Correct = %d ; Incorrect = %d ; Unattempted = %d",correct,incorrect,unattempted);
    return 0;
}

But get the output as
C#
Enter Answer for Q.1: A
Correct
Enter Answer for Q.2:Wrong
Correct = 1 ; Incorrect = 1 ; Unattempted = 0
Process returned 0 (0x0)   execution time : 2.281 s
Press any key to continue.



Can somebody please help me with the code.
Posted
Comments
[no name] 1-Jan-16 12:34pm    
Use %s instead of %c
Arnav Varshney 3-Jan-16 7:42am    
Thanks
[no name] 3-Jan-16 9:02am    
You are welcome!

1 solution

We could...but you wouldn't learn much from that.
Instead, use the debugger.

Put a breakpoint on the first line in the main function, and run your code through the debugger. Then look at your code and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900