cout << "How many questions are there going to be on this exam?" << endl;
cout << ">>";
getline(cin, totalquestions);
This small piece of code comes from a function in a class that I have created and I need totalquestions
to be an int so that it can run through a for loop and keep asking the total amount of questions that I have asked.
question q;
for(int i = 0; i < totalquestions; i++)
{
q.inputdata();
questions.push_back(q);
}
Where does this piece of code comes to play? Does anyone have any idea to make this work?
Use
cin >> totalquestions;
Check the errors too
if (!(cin >> totalquestions))
{
// handle error
}