So I am working on this program, and i have it mostly complete. I am just having trouble with running the loop again. If i run the loop again, it messes up by displaying both of the questions in the function at the same time.
And after the program is finished, i need to display all of the iterations at the same time.
// This program will gather the information for the quizzes that have been taken in a course to date
and // output the information into a report on the screen.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Function Prototypes
void getQuiz(string&, int&, int&);
int main()
{
char grade;
char ans = 'Y';
string name;
int quiz_number = 0;
int score;
int poss_score;
int counter = 1;
double percentage;
// Explain what the program will do
cout << "This program will ask the user to enter the name of a quiz, the score aquired, and the
total possible score.\n";
cout << "It will display a report that will show the quiz number, the name, the points, total,
percentage, and the letter grade." << endl << endl;
do {
// Display count
cout << counter;
cout << endl << endl;
// Call function
getQuiz(name, score, poss_score);
// Accumulate the number of times the loop is run
counter++;
cout << "Would you like to add another quiz? (Y) or (N)" << endl;
cin >> ans;
} while (ans == 'y' || ans == 'Y');
cout << endl << endl;
// Calculate the percentage
percentage = score * 100 / poss_score;
// Get the letter grade
if (percentage <= 100 && percentage >= 90)
grade = 'A';
else if (percentage <= 89 && percentage >= 80)
grade = 'B';
else if (percentage <= 79 && percentage >= 70)
grade = 'C';
else if (percentage <= 69 && percentage >= 60)
grade = 'D';
else if (percentage <= 59)
grade = 'F';
// Display the results in a table
cout << setw(5) << " Quiz" << setw(20) << " Title" << setw(20) << " Points" << setw(10) << "
Total" << setw(10) << " Percent" << setw(10) << " Grade" << endl << endl;
cout << setw(5) << counter << setw(20) << name << setw(20) << score << setw(10) << poss_score <<
setw(10) << percentage << setw(10) << grade << endl;
return 0;
}
void getQuiz(string& name, int& score, int& poss_score)
{
// Get the name of the quiz
cout << "\nWhat is the name of the quiz? " << endl;
getline(cin, name);
cout << "\nWhat was the score aquired? " << endl;
cin >> score;
cout << "\nWhat was the total possible score acheivable? " << endl;
cin >> poss_score;
}