hi everyone, help me to loop this program.

i am very greatful for this site because i know my question will be answered at last. i have been trying to loop a program for a long time. but it seems the loop doesnt work. the program works fine without loops but anytime i insert the loop, the program terminates incorrectly. i have been lean from the book "learn to program with c++" by john smiley. this is the source code:


//Grades.cpp

#include <iostream>
#include <string>

int main()
{
using namespace std;

const float ENGLISH_MIDTERM_PERCENTAGE = .25;
const float ENGLISH_FINALEXAM_PERCENTAGE = .25;
const float ENGLISH_RESEARCH_PERCENTAGE = .30;
const float ENGLISH_PRESENTATION_PERCENTAGE = .20;
const float MATH_MIDTERM_PERCENTAGE = .50;
const float MATH_FINALEXAM_PERCENTAGE = .50;
const float SCIENCE_MIDTERM_PERCENTAGE = .40;
const float SCIENCE_FINALEXAM_PERCENTAGE = .40;
const float SCIENCE_RESEARCH_PERCENTAGE = .20;

int midterm = 0;
int finalExamGrade = 0;
int research = 0;
int presentation = 0;
float finalNumericGrade = 0;
char finalLetterGrade;
char response[256];
string moreGradesToCalculate;



cout << "Do you want to calculate a grade? ";
cin >> moreGradesToCalculate;


for (int i = 0; i < moreGradesToCalculate.length(); i++) {
moreGradesToCalculate[i] = toupper (moreGradesToCalculate[i]);
}

while (moreGradesToCalculate == "YES") {


//what type of student are we calculating?
cout << "Enter student type " << "(1=English, 2=Math, 3=Science): ";

cin.getline(response,256);

if (strlen(response) == 0)
{
cout << "You must select a Student Type...";
return 1;
}


if ((atoi(response) < 1) | (atoi(response) > 3))
{
cout << response <<"-is not a valid student type";
return 1;
}

//student type is valid, now let's calculate the grade

switch(atoi(response)) //switch begins
{
//Case is an English Student
case 1:
cout << "Enter the Midterm Grade: ";
cin.getline(response,256);
midterm = atoi(response);
cout << "Enter the Final Examination Grade: ";
cin.getline (response,256);
finalExamGrade = atoi(response);
cout << "Enter the Research Grade: ";
cin.getline(response,256);
research = atoi(response);
cout << "Enter the Presentation Grade: ";
cin.getline(response,256);
presentation = atoi(response);

finalNumericGrade = (midterm * ENGLISH_MIDTERM_PERCENTAGE) +
(finalExamGrade * ENGLISH_FINALEXAM_PERCENTAGE) +
(research * ENGLISH_RESEARCH_PERCENTAGE) +
(presentation * ENGLISH_PRESENTATION_PERCENTAGE);

if(finalNumericGrade >= 93)
finalLetterGrade = 'A';

else
if((finalNumericGrade >=85) & (finalNumericGrade < 93))
finalLetterGrade = 'B';

else
if((finalNumericGrade >=78) & (finalNumericGrade < 85))
finalLetterGrade = 'C';

else
if((finalNumericGrade >=70) & (finalNumericGrade < 78))
finalLetterGrade = 'D';

else
if(finalNumericGrade < 70)
finalLetterGrade = 'F';
cout << endl << "***ENGLISH STUDENT***" << endl;
cout << "Midterm grade is: " << midterm << endl;
cout << "Final Exam Grade is: " << finalExamGrade << endl;
cout << "Research grade is : " << research << endl;
cout << "Presentation grade is: " << presentation << endl << endl;
cout << "Final Numeric Grade is: " << finalNumericGrade << endl;
cout << "Final Letter Grade is: " << finalLetterGrade << endl;
break;

//Case 2 is a Math Student
case 2:
cout << "Enter the Midterm Grade: ";
cin.getline(response,256);
midterm = atoi(response);
cout << "Enter the Final Examination Grade: ";
cin.getline(response,256);
finalExamGrade = atoi(response);

finalNumericGrade = (midterm * MATH_MIDTERM_PERCENTAGE)+
(finalExamGrade * MATH_FINALEXAM_PERCENTAGE);

if (finalNumericGrade >=90)
finalLetterGrade = 'A';

else
if ((finalNumericGrade >=83) & (finalNumericGrade <90))
finalLetterGrade = 'B';

else
if ((finalNumericGrade >=76) & (finalNumericGrade <83))
finalLetterGrade = 'C';

else
if ((finalNumericGrade >=65) & (finalNumericGrade <76))
finalLetterGrade = 'D';

else
if (finalNumericGrade <65)
finalLetterGrade = 'F';

cout << endl << " ***MATH STUDENT***" << endl << endl;
cout << "Midterm grade is: " << endl;
cout << "Final Exam is: " << finalExamGrade << endl;
cout << "Final Numeric Grade is: " << finalNumericGrade << endl;
cout << "Final Letter Grade is: " << finalLetterGrade;
break;


//Case 3 is a Science Student
case 3:
cout << "Enter the Midterm Grade: ";
cin.getline(response,256);
midterm = atoi(response);
cout << "Enter the Final Examination Grade: ";
cin.getline(response,256);
finalExamGrade = atoi(response);
cout << "Enter the Research Grade: ";
cin.getline(response,256);
research = atoi(response);

finalNumericGrade = (midterm * SCIENCE_MIDTERM_PERCENTAGE)+
(finalExamGrade * SCIENCE_FINALEXAM_PERCENTAGE)+
(research * SCIENCE_RESEARCH_PERCENTAGE);
if (finalNumericGrade >=90)
finalLetterGrade = 'A';

else
if ((finalNumericGrade >=80) & (finalNumericGrade <90))
finalLetterGrade = 'B';

else
if ((finalNumericGrade >=70) & (finalNumericGrade <80))
finalLetterGrade = 'C';

else
if ((finalNumericGrade >=60) & (finalNumericGrade <70))
finalLetterGrade = 'D';

else
if (finalNumericGrade <60)
finalLetterGrade = 'F';

cout << endl << "***SCIENCE STUDENT***" << endl << endl;
cout << "Midterm grade is: " << midterm << endl;
cout << "Final Exam Grade is: " << finalExamGrade << endl;
cout << "Research grade is: " << research << endl;
cout << "Final Numeric Grade is: " << finalNumericGrade << endl;
cout << "Final Letter Grade is: " << finalLetterGrade;
break;

default:
cout << response << "-is not a valid student type";
return 1;
//end of switch
}
cout << endl << endl << "Do you have another grade to calculate? ";
cin >> moreGradesToCalculate;

for (int i = 0; i < moreGradesToCalculate.length(); i++) {
moreGradesToCalculate[i] = toupper (moreGradesToCalculate[i]);
}
}
cout << "Thanks for using the Grades Calculation Program!";

system ("pause");
return 0;
} // end of main


i am looking forward to getting an answer soon. thanks in advance
What does "terminates incorrectly" mean?

One common problem is that you mix the user input operator. Read this:

http://www.cplusplus.com/articles/S3wTURfi/
if i type "yes" to accept to calculate for a new grade. this is what i get:

Enter student type (1=English, 2=Maths, 3=science): you must select a student type....


after that the program will terminate
thank u very much! Coder777. the article have helped me solve it. you are amazing.
Topic archived. No new replies allowed.