hello
How can i make the rand function to generate a random number every time the loop is repeated ?
this code is doing: generating examples for subtraction (eg 15-4 =) into 20,examples are generated until the user presses 1.
The user enters the results of the examples.
The program prints for each result whether it is correct or incorrect.
(sorry for my low english)
Code:
#include <stdio.h>
int main(void)
{
int res,range,end,resC;
srand(time(0));
while(end != 1)
{
int num1,num2;
while(num1<num2)
{
num1 = rand() % 20;
num2 = rand() % 20;
}
printf("%d - %d = ",num1,num2);
scanf("%d",&res);
resC = num1 - num2;
if(res != resC)printf("the result is incorrect\n");
if(res == resC)printf("the result is correct\n");
printf("to exit, press 1 and to continue press another number\n");
scanf("%d",&end);
}
system("pause");
return 0;
}