I'm taking an Intro to C Programming elective this semester and I just can't figure this problem out. I've done a lot of website coding with PHP so I thought I was good at this haha. Guess not.
Everything works correctly except for some reason the CorrectProblems and IncorrectProblems integers are returning some absurdly high numbers at the end, no matter how many I do in fact get Correct/Incorrect. Am I just missing something obvious?
It prompts the right number of questions, calculates time correct, outputs random numbers fine... it just won't get Incorrect/Correct right, and it's throwing off the score at the end.
Pleaaaaaaase help I can't figure it out. I've tried using CorrectProblems++; / CorrectProblems += 1; / CorrectProblems = CorrectProblems + 1; to increment it, but they all return the same stupidly high numbers.
Everything works correctly except for some reason the CorrectProblems and IncorrectProblems integers are returning some absurdly high numbers at the end, no matter how many I do in fact get Correct/Incorrect. Am I just missing something obvious?
It prompts the right number of questions, calculates time correct, outputs random numbers fine... it just won't get Incorrect/Correct right, and it's throwing off the score at the end.
Pleaaaaaaase help I can't figure it out. I've tried using CorrectProblems++; / CorrectProblems += 1; / CorrectProblems = CorrectProblems + 1; to increment it, but they all return the same stupidly high numbers.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
//Declare variables
int NumberofProblems;
int CorrectProblems, IncorrectProblems;
int N1, N2;
int Solution, ProblemX, Guess;
int Score;
//Seed the random number generator
srand(time(0));
//Prompt for Number of Problems to answer
printf("How many problems do you want?\n");
scanf("%d",&NumberofProblems);
//Start problems counter at one
ProblemX = 1;
//While loop to present requested # of problems
int start = time(0);
while (ProblemX <= NumberofProblems)
{
//Select two random numbers
N1 = rand()%13;
N2 = rand()%13;
//Prompt question
printf("Answer: %d x %d = \n",N1,N2);
scanf("%d",&Guess);
//Find solution
Solution = N1 * N2;
//See if user answer equals solution
if (Guess == Solution)
{
//If so, output "Correct" and add one to CorrectProblems
printf("Correct!\n\n");
CorrectProblems += 1;
} else if (Guess != Solution) {
//If not, output "Incorrect" and give correct answer
printf("Incorrect, %d x %d = %d\n\n",N1,N2,Solution);
IncorrectProblems += 1;
}
//Increment Problem #
ProblemX++;
}
//All problems have been answered, stop timer and get total time spent
int end = time(0);
int timespent = end - start;
//Output results
printf("You got %d problems correct and %d problems incorrect in %d seconds.\n",CorrectProblems,IncorrectProblems,timespent);
//Calculate score
Score = (timespent + 5) * IncorrectProblems;
//Output score
printf("Your final score is %d!\n",Score);
system("pause");
return 0;
}