Hey all. So I want this program to ask the user if they have another student to input. If yes, then go through the class again, if not, exit the program. I don't know how to go about doing that... please help!! Thanks in advance
/*
write a program using classes to ask the user for the student's name, grade in 3 subjects, and print the data
in a nice table
*/
#include <iostream>
#include <string>
usingnamespace std;
//takes and prints info about the student
class Student
{
string name; //name of student
int gradeEng = 0, gradeMath = 0, gradeSci = 0; //grades in each subject
int total; //total of all grades
public:
//takes the student's name
void takeData();
//takes grades of the student and finds total
int grades();
Student()
{
takeData();
grades();
}
//returns values to print
string getName() { return name; }
int getTotal() { return total; }
};
int main()
{
Student student1;
cout << "Name: " << student1.getName() << endl;
cout << "Total grade = " << student1.getTotal() << endl;
system("pause");
return 0;
}
void Student::takeData()
{
cout << "Enter the student's name: ";
getline(cin, name);
}
int Student::grades()
{
cout << "Enter each grade for the applicable subject:" << endl;
cout << "English: ";
cin >> gradeEng;
cout << "Math: ";
cin >> gradeMath;
cout << "Science: ";
cin >> gradeSci;
cout << endl;
total = gradeEng + gradeMath + gradeSci;
return total;
}
/*
write a program using classes to ask the user for the student's name, grade in 3 subjects, and print the data
in a nice table
*/
#include <iostream>
#include <string>
usingnamespace std;
//takes and prints info about the student
class Student
{
string name; //name of student
int gradeEng = 0, gradeMath = 0, gradeSci = 0; //grades in each subject
int total; //total of all grades
char yes;
public:
//takes the student's name
void takeData();
//takes grades of the student and finds total
int grades();
Student()
{
/* The new loop ***********************************/
do
{
takeData();
grades();
cout << "Name: " << name << endl;
cout << "Total = " << total << endl << endl;
cout << "Do you want to enter another student? (Y/N) ";
cin >> yes;
} while (yes == 'y' || yes == 'Y');
/***********************************************/
}
//returns values to print
string getName() { return name; }
int getTotal() { return total; }
};
void Student::takeData()
{
cout << "Enter the student's name: ";
getline(cin, name);
}
int Student::grades()
{
cout << "Enter each grade for the applicable subject:" << endl;
cout << "English: ";
cin >> gradeEng;
cout << "Math: ";
cin >> gradeMath;
cout << "Science: ";
cin >> gradeSci;
cout << endl;
total = gradeEng + gradeMath + gradeSci;
return total;
}
int main()
{
Student student1;
//cout << "Name: " << student1.getName() << endl;
//cout << "Total grade = " << student1.getTotal() << endl;
system("pause");
return 0;
}