Create a menu-driven program that allows the following

This is due soon and I cant seem to get it to work. I am working with Dev-C++. We are suppose to do the following and no matter what I have tried I can seem to get it to work and now I have to start all over. PLEASE SOMEONE HELP!!!

Write a C++ program that is menu-driven that allows for the following menu choices:
1.Load an exam: Loading an exam should prompt the user for an exam file. If no file exists, it should allow the user to specify a different file. Upon a successful load of an exam, the user should be presented with the menu again.

2.Display exam: The program should simply display each question, its point value, and the answer to the screen. (The functionality of actually taking the exam will be created in Week 5). Upon displaying the exam to the screen, the user should be presented with the menu again.

3.Quit: Quit the program gracefully by displaying a "thank you" message to the user, and ensure that all files have been closed along with any other housekeeping that should be done as your program shuts down.

Consider creating a class exam that will hold the actual exam and provide behavior such as loadExam and also displayExam. This class will be enhanced next week.

I was able to get this far:

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;


int main()
{
int menuChoice;
int exit = 1;

while (exit == 1)
{
cout << "1) Load an Exam\n"
<< "2) Display Exam\n"
<< "3) Quit\n";
cin >> menuChoice;

string txtFile;

switch (menuChoice)
{
case 1:
cout << "Enter in the file you want to import: " << endl;
cin >> txtFile;
cout << "Your file is saved under the name: " << txtFile << endl;
break;
case 2:
cout << txtFile;
break;
case 3:
cout << "Thank you for visiting!" << endl;
exit = 0;
break;
default:
cout << "File could not be found!" << endl;
exit = 0;
break;

}



}
return 0;
}


Now I am trying to get it to print out the contents that is in the .txt file by option 2 but its not working.

Last edited on
no code no help.
This is how far I have gotten but I cant seem to get it to run without any errors and it wont let me import an exam file.



#include <iostream>
#include <string>
#include <fstream>
using namespace std;


string LoadExam();
string DisplayExam();


int main()
{
int choice;

do
{
cout << "1) Load an Exam" << endl;
cout << "2) Display the Exam" << endl;
cout << "3) Quit Program" << endl;
cin >> choice;

switch(choice)
{
case 1:
LoadExam();
break;
case 2:
void printDisplayExam();
break;
case 3:
cout << "Thank you for visiting. See you again later..." << endl;
break;
default:
cout << "Invalid Option" << endl;
}
} while (choice >= 1 || choice <= 3);






return 0;
}


void printDisplayExam()
{
string type;
string question;
char answer;
int NumbQuestions;
int valueOfQuestion


if (type == "TF"){
cout << "Enter in the question:" << endl;
cin.ignore();
getline (cin, question);
cout << "Enter in the answer:" << endl;
cin >>answer;
cout << NumbQuestions << endl;
cout << type << " " << valueOfQuestion << endl;
cout << question << endl;
cout << answer << endl;
}

if(type == "MC"){
cout << "Enter in the question:" << endl;
cin.ignore();
getline (cin, question);
cout << "Enter in the number of choices:" << endl;
cin >> numbOfChoices;
cout << "Enter in the options:" << "\nPlace a space before each entry"<< endl;

for(int i = 0; i < numbOfChoices; i++){
cin.ignore();
getline (cin, opt[i]);
}

cout << "Enter in the answer:" << endl;
cin >> answer;
cout << NumbQuestions << endl;
cout << type << " " << valueOfQuestion << endl;
cout << numbOfChoices << endl;
cout << question << endl;

for(int j = 0; j < numbOfChoices; j++){
cout << opt[j] << endl;
}

cout <<"Answer: "<< answer << endl;
}
}
MoleskiH25,

I will first suggest that you refer back to the program requirements because you have missed most of the requirements.

it wont let me import an exam file

this is because you have not written any code to open a file to read.

Some of the errors you are having:
string DisplayExam();
good proto type, but the function is
void printDisplayExam()
They do not match.

The function printDisplayExam() is asking the user for the question when it should be outputting the question. There is missing punctuation for int valueOfQuestion. Where do you get type from to compare to TF and MC? And in the if block for MC you have a for loop with the line getline(cin,opt[i]); yet you have never defined opt.

BTW thank you for your post. I had fun playing with the program.

Hope that helps,

Andy
I was able to get the main menu to print out but when I choose the first option "Load an Exam" it displays to enter in the file but then terminates the program.

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;


int main()
{
int menuChoice;
string txtFile;
string mainMenu;


cout << "Please select a choice: \n1) Load an Exam \n2) Display Exam \n3) Quit" << endl;
cin >> menuChoice;

switch (menuChoice)
{
case 1:
cout << "Please enter in the file name:" << endl;
getline(cin, txtFile);
break;
case 2:
cout << txtFile << endl;
break;
case 3:
cout << "Thank you for visiting!" << endl;
}




return 0;
}
Topic archived. No new replies allowed.