#include <iostream>
#include <string>
#include <ctime>
usingnamespace std;
int main()
{
srand (time(NULL));
int grade, operands[2], userAnswer;
string quiz[20], name;
char answer[12], userchoice( '\0' );
cout << "What is your name?\n";
cin >> name;
cout << "Were going to take a quiz, are you ready? <y/n>\n";
cin >> answer[0];
if(answer[0] == 'y' || answer[0] == 'Y')
{
cout << "Ok lets get started " << name << endl;
cout << "First lets do a math problem.\n";
operands[0] = rand()%50;
operands[1] = rand()%20;
/*******************first question********************************/
do
{
cout << "What is " << operands[0] << " + " << operands[1] << " ?\n";
cin >> userAnswer;
if(userAnswer==operands[0] + operands[1])
{
cout << "You got the Problem right, off to the next question\nYou ready?\n";
cin >> answer[1];
}
else
{
cout << "Problem incorrect\n";
cout << "Would you like to try again?\n";
cin >> userchoice;
}
}while(userchoice == 'y' || userchoice == 'Y');
/*********SECOND?***************/
if(answer[1] == 'y' || answer[1] == 'Y')
{
do
{
cout << "Who was the president of the united states in 1865?\n";
if(quiz[19]=="Abraham Lincoln" || quiz[19] == "abraham lincoln")
cout << "Good job, off to the next question\n";
else
{
cout << "Problem incorrect\n";
cout << "Would you like to try again?\n";
cin >> userchoice;
}
}while(userchoice == 'y' || userchoice == 'Y');
}
}
system("pause");
return 0;
}
is this a correct way to use the char and when i run this program, after you get the first question right it ask are you ready for the next question you say 'y' and it takes you to the next question but it automaticly tells you that its wrong and skips to the system("pause") any help appriciated thank you
The reason why it is skipping to the system("pause") is because on line 49 you ask the question cout << "Who was the president of the united states in 1865?\n";
But you never let the user answer the question you just go straight into check if (quiz[19] == "Abraham Lincoln"). So you need to add in a cin >> quiz.
Also I would recommend you switch to using strings since they are much easier to manage and you are using C++ ;p
thank you sir, i didint even relize that haha, i also just changed this part to a multiple choice one, i also have a nother question if i could, when i answer the first question wrong, then do the question again and get it right when i say yes to going to the next question, it just repeats the first question. any ideas on that?
Because you when get the answer wrong the first time you set userchoice to equal 'y' or 'Y'. So then you do the first question again and when you get it right it will keep on looping through the first question over again over since userchoice is == 'y' from the first time you did the question.
To fix this you will want to make userchoice = ' ' equal to a blank char at the beginning of the do while loop.
Hope that makes sense getting kinda late here and my mind is wandering lol.
thank you ill try it, im still learning C++ and im just learning from the internet and i dont understand things the first time around. haha thanks thou,