quiz system, please help

Hi, i would like to ask you if anyone here can help me. So my program is a Quiz but, the questions should be multiple choice and the questions were coming from a text file. After the user answers 10 questions , it will then compute for total correct answers.I have a code here but it does not get the questions to a text file. Please help me.

#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main()
{
vector<string> questionlist;
vector<string>::const_iterator iter;
string add;
int removeNumber;
int choice;

mainMenu:
int number = 0;

cout << "\n1. Take Test." << endl;
cout << "\n2. Add question to the list." << endl;
cout << "\n3. Remove a question from the list.\n\n" << endl;

cout << "Choose: ";
cin >> choice;

switch(choice)
{
case 1:
for(iter = questionlist.begin(); iter != questionlist.end(); iter++)
{
cout << "\n" << *iter << endl;
}


goto mainMenu;


case 2:

cout << "\nWrite the question:";
cin.ignore();
getline(cin,add);

questionlist.push_back(add);
sort(questionlist.begin(), questionlist.end());
cout << "\nQuestion added succesfully." << endl;

goto mainMenu;

case 3:

for(iter = questionlist.begin(); iter != questionlist.end(); ++iter)
{
++number;
cout << number << ". " << *iter << endl;
}

cout << "\nType the number of the question you want to remove below." << endl;
cout << "Remove number: ";
cin >> removeNumber;

questionlist.erase((questionlist.begin() + removeNumber - 1));

cout <<"\nQuestion removed." << endl;
number = 0;
for(iter = questionlist.begin(); iter != questionlist.end(); ++iter)
{
++number;
cout << number << ". " << *iter << endl;
}

goto mainMenu;
}
return 0;
}

That's not really the best way to approach this.

You want to consider holding the questions, possible answers and some indicator of what is right in some data structure.

The program then just presents the questions and multiple answers from the data structure.

If you find yourself repeating sections of code as you're doing for each question, it's time to step back and attempt to do things in a more general way.
Topic archived. No new replies allowed.