Question: C++ I am receiving errors with my program. This program takes user input and stores it into a file. I am stuck on the True/False

C++ I am receiving errors with my program. This program takes user input and stores it into a file. I am stuck on the True/False function due to errors. I have posted my full code. the Errors received and the True/False function pulled out for fast examination. Please assist me I am getting close to this deadline and need to get this working. My code:

#include "stdafx.h"

#include

#include

#include

using namespace std;

class TestBank

{

public:

void TrueFalse(ofstream&);

void MultipleChoice(ofstream&);

};

int main()

{

TestBank bankObj;

ofstream test;

int testNumber, typeOfQuestion;

char yesOrNo;

// Create test bank file.

test.open("C:\\temp\\testBankFile.txt");

if (test.is_open())

{

cout << "How many questions would you like to create? ";

cin >> testNumber;

test << testNumber << endl;

int nextNum = 1;

//create the test bank

for (int i = testNumber; i > 0; --i)

{

cout << endl << "What type of question will #" << nextNum++

<< " be? 1=T/F or 2=multiple choice: ";

cin >> typeOfQuestion;

test << typeOfQuestion << endl;

switch (typeOfQuestion)

{

case 1: bankObj.TrueFalse(test);

break;

case 2: bankObj.MultipleChoice(test);

}

}

test.close();

}

else

{

cout << "Unable to create test bank";

}

system("pause");

return 0;

}

// function to create true/false question

void TestBank::TrueFalse(ofstream& thefile)

{

int points;

string question;

char answer, yn;

do

{

cout << " How many points does this question worth? Enter: ";

cin >> points;

cin.ignore();

cout << " Please enter the question: ";

getline(cin, question);

cout << " Please enter the answer True or False ?";

cin >> answer;

cin.ignore();

cout << "Would like to make any correction ? ";

cin >> yn;

} while (yn == 'y');

//Write all information into the file

//Complete the remaining code here

thefile << points << endl;

thefile << question << endl;

thefile << answer << endl;

}

//Now you have to complete function MultipleChoice()

// function to create multiple choice question

void TestBank::MultipleChoice(ofstream& theFile)

{

}

Errors:

Severity Code Description Project File Line Suppression State Warning C4101 'yesOrNo': unreferenced local variable CS215_Joseph_Hoffman_IP3 c:\users\aceis\source epos\cs215_joseph_hoffman_ip3\cs215_joseph_hoffman_ip3.cpp 17 Error LNK1104 cannot open file 'C:\Users\ACEis\source epos\CS215_Joseph_Hoffman_IP3\Debug\CS215_Joseph_Hoffman_IP3.exe' CS215_Joseph_Hoffman_IP3 C:\Users\ACEis\source epos\CS215_Joseph_Hoffman_IP3\LINK 1

So if I comment out the three lines of code to insert into the file it works but it still is not right. It mashes up the question for changes and the end of the program so if you hit y or n the program just ends. Should not do this. True/False function with the insert file lines commented out:

void TestBank::TrueFalse(ofstream& thefile) { int points; string question; char answer, yn; do { cout << " How many points does this question worth? Enter: "; cin >> points; cin.ignore(); cout << " Please enter the question: "; getline(cin, question); cout << " Please enter the answer True or False ?"; cin >> answer; cin.ignore(); cout << "Would like to make any correction ? "; cin >> yn; } while (yn == 'y'); //Write all information into the file (commented out for testing) //thefile << points << endl; //thefile << question << endl; //thefile << answer << endl; //Complete the remaining code here } 

This is not working correctly needs to insert to the file if n for No is chosen. The program should ask the following in order for the true/false section:

*How many points does this question worth? Enter: *Please enter the question: *Please enter the answer True or False? *Would like to make any correction ?

If 'y' is selected it should loop back to the beginning to retry if 'n' the program should write all the inputs to the file.

how do I properly do this? What am I doing wrong? I really need to get this going.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!