You need to pay close attention to the detail.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ( ) {
int mark = 0;
int count = 0;
do
{
int no1 = rand() % 50 + 1;
int no2 = rand() % 50 + 1;
int pcAns = no1 + no2;
printf("%d + %d = ", no1, no2);
int userAns;
int scanStatus = scanf("%d", &userAns); //!! yes, you forgot this assignment
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 enter yur answer in digit form\n");
}
count++;
} while (count <= 10);
printf("You scored mark %d in %d attempts\n", mark, count);
}
Results
Code:
$ gcc bar.c
$ ./a.out
34 + 37 = 55
Sorry the correct answer is 71
28 + 16 = a
Please enter yur answer in digit form
44 + 36 = a
Please enter yur answer in digit form
37 + 43 = 80
Congratulation, your have entered the correct answer!!
50 + 22 = 72
Congratulation, your have entered the correct answer!!
13 + 28 = 41
Congratulation, your have entered the correct answer!!
41 + 10 = 51
Congratulation, your have entered the correct answer!!
14 + 27 = 38
Sorry the correct answer is 41
41 + 27 = 68
Congratulation, your have entered the correct answer!!
23 + 37 = 60
Congratulation, your have entered the correct answer!!
12 + 19 = 31
Congratulation, your have entered the correct answer!!
You scored mark 70 in 11 attempts