Allright pretty much i just need help on loop
Basically, Im supposed to make a program that involves two games: Arithmetic and Factorization. The latter is what I'm having trouble with
Here's what I've written.
This is the factorization function, which it will return a value in seconds to main (dont worry about this part)
Code:
double factorGAME (int max, int quantity) {
int correct, a, b, i, guesses=1, answer, points;
int wrong_ans=0;
//This is will start the time
double start = time(0);
for (i=1; i <= quantity; i++){
//Two random numbers will be set the question
int x = rand()%max+1;
int y = rand()%max+1;
correct = x*y;
printf("Please factor %d\n", correct);
scanf("%d %d", &a, &b);
answer = a*b;
if (answer == correct){
if (a == x && b == y);
else if (a == y && b == x);
else
printf("Sorry, that is not the factorization we are looking for\nPlease try again.\n");
}
//when the user types the wrong answer, this will display
else{
printf("Sorry, %d x %d does NOT equal %d\n", a, b, correct);
printf("Please try again\n");
guesses+=1;
//it adds 5 seconds penalty
wrong_ans= wrong_ans + 5;
//the loop will set the program to repeat itself until the right answer is given
while (answer != correct) {
scanf("%d %d", &a, &b);
answer = a*b;
if (answer == correct);
else
{
printf("Sorry, %d x %d does NOT equal %d\n", a, b, correct);
printf("Please try again\n");
guesses+=1;
}
}
}
printf("Correct, great job!\n");
printf("You got the factorization in %d guesses\n", guesses);
}
// Ends the timer for factorization game
double end = time(0);
double time_spent = end + wrong_ans - start;
double performance;
performance = time_spent / quantity;
return performance;
}
The prob is that when a number, like 24 for instance, it causes prob.
there are multiple factors that sometime doesnt match up the user's answer to the comp
I want the output to write something like:
...
Please Factor 124
4 31
Sorry, that is not the factorization we are looking for.
Please try again
2 62
Correct, great job!
Any solutions?