Hello,
I am having trouble with my code. I am making a computer assistance program that outputs multiplication problems. At this point, I want the user to type 'y' when he correctly answers the question to move on to the next question. My code is working but it is not outputting the right info on the console window. It doesn't put out responses like "good job" after the first question and sometimes the questions are duplicated. How can I fix this so that the user can only press 'y' when the question is correct?
thank you
Line 11, 98: Your calls to srand() are in the wrong place. srand() should be called ONCE at the beginning of main. Multiple calls to srand() cause the random number generator to be reset to produce the same sequence of numbers if called within the same second.
int main()
{ char done = 'y';
int answer;
int userAnswer;
srand(time(0)); // Call ONCE at the beginning of main
do
{ answer = question();
cin >> userAnswer;
if (userAnswer == answer)
correctAnswer();
else
incorrectAnswer();
cout << "type 'y' for another question" << endl;
cin >> done;
}
while (done == 'y');
return 0;
}
What's the point of newQuestion()? It does exactly the same thing as question().
I have to create a function to create a new question for my program for my projects.
The way I would tackle this is to use your current question() function as a model, rename it questionMultiply() and cut/copy/paste/modify a new one called questionAdd() as an example. From there the world is at your feet. :)