i have a text file that i read in which contains multiple choice questions. for example:
Is east on left or right?
A) left
B) right
C) none of the above
What symbol is used for cout?
A) <<
B) >>
C) >
D) <
What is used for cin?
A) >>
B) <
C) >
D) <<
how can i switch the order of the questions every time it compiles. My code is below. I'm not familiar much with vectors and need help to know how to switch up the order of questions. Thanks in advance.
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
char c;
char d;
string line_;
ifstream file_("mpchoice.txt");
vector<string> lines;
if (file_.is_open())
{
while (getline(file_, line_))
{
cout << line_ << '\n';
lines.push_back(line_);
}
file_.close();
}
cout << "What is your response for number 1\n";
cin >> c;
if (c == 'A')
cout << "That's wrong\n";
cout << "What's your response for the second question\n";
cin >> d;
if (d == 'A'){
cout << "That's correct\n";
}
else
cout << "That's wrong\n";
return 0;
}
Aucun commentaire:
Enregistrer un commentaire