how do i get my program to repeat non stop? i want it to keep asking me to input the same information for multiple students. and not stop after i input once. can someone help please? i really appreciate all the help thank you guys.
enter code here
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int midterm=0;
int final=0;
cout << "please enter midterm grade: ";
cin >> midterm;
while (midterm < 0 || midterm > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
cin >> midterm;
}
cout << "please enter final grade: ";
cin >> final;
while (final < 0 || final > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. Please enter grade";
cin >> final;
}
int total;
total = final midterm;
if (total > 360 && total <= 400)
{
cout << "your letter grade is A";
}
else if (total > 320 && total <= 360)
{
cout << "your letter grade is B";
}
else if (total > 280 && total <= 320)
{
cout << "your letter grade is C";
}
else if (total > 240 && total <= 280)
{
cout << "your letter grade is D";
}
else if (total <= 240)
{
cout << "your letter is F";
}
}
CodePudding user response:
Put your whole code in a loop that never stops.
Example:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
while(true) {
int midterm=0;
int final=0;
cout << "please enter midterm grade: ";
cin >> midterm;
while (midterm < 0 || midterm > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. please enter grade: ";
cin >> midterm;
}
cout << "please enter final grade: ";
cin >> final;
while (final < 0 || final > 200)
{
cout << "Please enter valid amount must be 0 or greater or 200 or less. Please enter grade";
cin >> final;
}
int total;
total = final midterm;
if (total > 360 && total <= 400)
{
cout << "your letter grade is A";
}
else if (total > 320 && total <= 360)
{
cout << "your letter grade is B";
}
else if (total > 280 && total <= 320)
{
cout << "your letter grade is C";
}
else if (total > 240 && total <= 280)
{
cout << "your letter grade is D";
}
else if (total <= 240)
{
cout << "your letter is F";
}
cout << "\n";
}
}
This question has been asked and answered before as well: How do I make my code Repeat instead of ending in c ?