Image

Imageaymelek wrote in Imagecpp

A Little Help??

I'm doing a program in the "Starting out with C++ 4th Edition" book by Tony Gaddis called the "Driver's License Program"

I have it kinda sorta working, but there are a few things that I just can't have it do:
1) the user can only input A, B, C, or D (a, b, c, or d) as the right answers
2) There is an array with the correct answers in it and I need to have it compare to the array the user inputs (the guesses)
3) and finally I have to tally up the right/wrong answers and put the final score at the bottom


Driver's License Exam Instructions

Please enter student's answers for each of the 20 questions
when prompted for the answer to the question, pressing Enter
after each answer to the appropriate question.
Please enter only an A, B, C, or D for each question.

Question 1: a
Question 2: a
Question 3: a
Question 4: a
Question 5: a
Question 6: a
Question 7: a
Question 8: a
Question 9: a
Question 10: a
Question 11: aa
Question 12: Question 13: a
Question 14: a
Question 15: a
Question 16: a
Question 17: a
Question 18: a
Question 19: a
Question 20: a


We're sorry. Better luck next time.

Driver's License Exam Report
Key: Question Number + (Correct Answer) + Your Answer
# 1(B) A # 2(D) A # 3(A) A # 4(A) A # 5(C) A
# 6(A) A # 7(B) A # 8(A) A # 9(C) A #10(D) A
#11(B) A #12(C) A #13(D) A #14(A) A #15(D) A
#16(C) A #17(C) A #18(B) A #19(D) A #20(A) A

Total correct: 6
Total incorrect: 14
Passing score is: 70%
Your score is: 30%



//TO DO:
//1) Create section for user to only input valid answer
//2) Tally up incorrect/correct
//3) Display final score; user score; totals



// Filename: driversLicense.cpp
// Programmer: Jenni Bemke
// Class: 276
// Section: DCE
// Assignment Name: Unit 07
// Due Date: 04/20/04

#include
#include

using namespace std;

int main()
{
ifstream answers; //declare file input variable
int highScore; //high score, passing score
const int SIZE = 20; // number of answers allowed
char correct[SIZE];


answers.open("driversLicense.txt", ios::in); //open file
if (!answers){ //check file for errors
cout << "Unable to open the file \"driversLicense.txt\" " << endl;
cout << "Terminating program." << endl;
cin.get();
}

else //if no errors found, start looping program
{
answers >> highScore; //read high score

cout << highScore;

while( !answers.eof() ) //loop until end of file
{
answers >> correct[SIZE]; //continue reading records

cout << correct[SIZE];
}
}

answers.close(); //close the file

//*** Get User Input ***

int wrong;
int right;

cout << endl;
cout << "\nDriver's License Exam Instructions" << endl;

cout << "\nPlease enter student's answers for each of the 20 questions\n";
cout << "when prompted for the answer to the question, pressing Enter\n";
cout << "after each answer to the appropriate question.\n";
cout << "Please enter only an A, B, C, or D for each question." << endl;

char guess[SIZE]; //declare user input array

for(int user=0; user < 20; user++)
{
cout << "\nQuestion " << (user + 1) << ": ";
cin >> guess[user];

//{
// if(user != 'A' && user != 'B' && user != 'C' && user != 'D')
// cout << "Invalid Answer. Please re-enter an answer: ";
// cin >> guess[user];
// else
// cout << "\nQuestion " << (user + 1) << ": ";
// cin >> guess[user];
//}
}

for (int i=0; i < SIZE; i++)
{
if (guess[i] == correct[i])
right++;
else
wrong++;
}

cout << "Total Right: " << right << endl;
cout << "Total Wrong: " << wrong << endl;


//int userScore; //user score
//int totalCorrect; //amount user got correct
//int totalIncorrect; //amount user got incorrect


// finalScore = userScore / highScore;

// if(finalScore < highScore)
// cout << "We're sorry. Better luck next time.";
// else
// cout << "Congratulations. You passed!";


// cout << "Driver's License Exam Report";
//cout << "\nKey: Question Number + (Correct Answer) + Your Answer";



//cout << "Total correct: " << totalCorrect << endl;
//cout << "Total incorrect: " << totalIncorrect << endl;
//cout << "Passing score is: " << highScore << "%";
//cout << "\nYour score is: " << userScore << endl;

return 0;
}



70
B
D
A
A
C
A
B
A
C
D
B
C
D
A
D
C
C
B
D
A


So I think that is about it... a lot... I know. If any of you have any suggestions that would be great. It's due on Monday so I pretty much have all weekend. Thanks a bunch!
Jen