Hey guys I'm making an addition/multiplication game for my intro to C class. The objective of the program is to ask the user, what's the max number that you want to use which will seed random numbers within that max range and how many different problems you want to do. When I run the program and do the math, it tells me that the sum is incorrect and provides me an answer that isn't correct and is usually a large number like "1254323." Can you guys point me in the right direction as to what I am doing wrong?
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(){
int maxNumber, num1, num2, sum, answer, problems, i;
srand(time(NULL));
//printf("Would you like 1)Addition or 2)Multiplication?\n")
printf("Enter your Max Number:");
scanf("%d", &maxNumber);
printf("How many problems do you want?\n");
scanf("%d", &problems);
sum = num1 + num2;
while(i != problems){
num1 = rand()%maxNumber;
num2 = rand()%maxNumber;
i++;
printf("What is %d + %d\n",num1, num2);
scanf("%d", &answer);
if(answer != sum){
printf("Sorry, that's incorrect, the answer is %d\n", sum);
}
else{
printf("Correct!\n");
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire