what is the best way to create exit a program? For example:
This program uses a while loop and then checks the inputed value before it enters it again. Is there a shorter better way to do this? Should I use a character or a number? This comes up a lot in my programs and I want to use the fastest, best method.
Code:
//grades
#include <iostream.h>
int main()
{
int count = 0;
int total = 0;
int average;
int grades = 0;
cout << "Please enter a grade(enter -1 to quit): \n";
cin >> grades;
while(grades != -1)
{total += grades;
count++;
cout << "Please enter a grade(enter -1 to quit): \n";
cin >> grades;}
average = total / count;
cout << "Class average is: " << average << endl;
return 0;
}