The following lines of codes are supposed to run smoothly without any error. However, after I debug for minutes, I got tired. I don't see any errors in my scripts. Can someone help me out? Its supposed to be a grades calculation program.
Code:#include <iostream> #include <string> using namespace std; int main() { //declaring english students fixed percentage of marks const float ENGLISH_MIDTERM_PERCENTAGE = 0.25; const float ENGLISH_FINALEXAM_PERCENTAGE = 0.25; const float ENGLISH_RESEARCH_PERCENTAGE = 0.30; const float ENGLISH_PRESENTATION_PERCENTAGE = 0.20; //end of english students fixed percentage //declaring maths students fixed percentage of marks const float MATH_MIDTERM_PERCENTAGE = 0.50; const float MATH_FINALEXAM_PERCENTAGE = 0.50; //end of math students fixed percentage //declaring science students fixed percentage of marks const float SCIENCE_MIDTERM_PERCENTAGE = 0.40; const float SCIENCE_FINALEXAM_PERCENTAGE = 0.40; const float SCIENCE_RESEARCH_PERCENTAGE = 0.20; //end of science students fixed percentage //declaring variables short midterm = 0; short finalExamGrade = 0; short research = 0; short presentation = 0; float finalNumericGrade = 0; char finalLetterGrade; char response[256]; string moreGradesToCalculate; //end of variables declaration //prompt user "whether they want to calculate grades" cout<< "Do you want to calculate a grade? Yes/No "; cin>> moreGradesToCalculate; //start of for loop for changing userinput to uppercase for (unsigned short a = 0; a < moreGradesToCalculate.length(); a++) { moreGradesToCalculate[a] = toupper (moreGradesToCalculate[a]); } //end of for loop //end of promting user //start of while loop while (moreGradesToCalculate == "YES") { //promting user for the type of students to calculate cout<< "*** 1) English, 2) Math, 3) Science *** "; cin.getline (response, 256); if (strlen(response) == 0) { cout<< "You must choose an option"; return 1; //return error } else if ((atoi(response) < 1) || (atoi(response) > 3)) { cout<< " - is not a valid option."; return 1; } //After user had input a valid student type, the following is to calculate the student's grade //start of switch statement switch (atoi(response)) { //case 1 is english student case 1: //Promt user for "midterm" grade cout<< "Please enter the Midterm Grade: "; cin.getline (response,256); midterm = atoi(response); //end of "midterm" grade //Promt user for "finalExamGrade" cout<< "Please enter the Final Examination Grade: "; cin.getline (response,256); finalExamGrade = atoi(response); //end of "finalExamGrade" //promt user for "research" grade cout<< "Please enter the research Grade: "; cin.getline (response,256); research = atoi(response); //end of "research" //Prompt user for "presentation" grade cout<< "Please enter the Presentation Grade: "; cin.getline (response,256); presentation = atoi(response); //end of "presentation" 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)) { finalNumericGrade = 'D'; } else if (finalNumericGrade < 70) { finalNumericGrade = 'F'; } //display student scores' informations cout<< "*** ENGLISH STUDENT ***" <<endl <<endl; cout<< "Midterm Grade is "<< midterm<< endl; cout<< "Final Exame is: "<< finalExamGrade<< endl; cout<< "Research is: "<< research<< endl; cout<< "Presentation is: "<< presentation<< endl<< endl; cout<< "Final Numeric Grade is: "<< finalNumericGrade<< endl; cout<< "Finak Letter Grade is: "<< finalLetterGrade; break; //end of english student //case 2 is a math student case 2: //Prompt user for "midterm" grade cout<< "Enter the Midterm Grade: "; cin.getline(response,256); midterm = atoi(response); //end of "midterm" grade //Promt user for "finalExamGrade" cout<< "Enter the Final Examination Grade: "; cin.getline(response,256); finalExamGrade = atoi(response); //end of "finalExamGrade" 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)) { finalNumericGrade = 'D'; } else if (finalNumericGrade < 65) { finalNumericGrade = 'F'; } //display student scores' informations cout<< "*** MATH STUDENT ***" <<endl <<endl; cout<< "Midterm Grade is "<< midterm<< endl; cout<< "Final Exame is: "<< finalExamGrade<< endl; cout<< "Research is: "<< research<< endl; cout<< "Presentation is: "<< presentation<< endl<< endl; cout<< "Final Numeric Grade is: "<< finalNumericGrade<< endl; cout<< "Finak Letter Grade is: "<< finalLetterGrade; break; //end of math student //case 3 is a Science student case 3: //Prompt user for "midterm" grade cout<< "Enter the Midterm Grade: "; cin.getline(response,256); midterm = atoi(response); //end of "midterm" grade //Promt user for "finalExamGrade" cout<< "Enter the Final Examination Grade: "; cin.getline(response,256); finalExamGrade = atoi(response); //end of "finalExamGrade" //Prompt user for "research" grade cout<< "Enter the Research Grade: "; cin.getline(response, 256); research = atoi(response); //end of "research" 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)) { finalNumericGrade = 'D'; } else if (finalNumericGrade < 60) { finalNumericGrade = 'F'; } //display student scores' informations cout<< "*** SCIENCE STUDENT ***" <<endl <<endl; cout<< "Midterm Grade is "<< midterm<< endl; cout<< "Final Exame is: "<< finalExamGrade<< endl; cout<< "Research is: "<< research<< endl; cout<< "Presentation is: "<< presentation<< endl<< endl; cout<< "Final Numeric Grade is: "<< finalNumericGrade<< endl; cout<< "Finak Letter Grade is: "<< finalLetterGrade; break; //end of science student //start of default for the switch statement default: cout<< response<< " - is not a valid student type"; return 1; } //end of switch statement cout<< endl<< endl<< "Do you have another grade to calculate? Yes/No "; cin>> moreGradesToCalculate; //start of for loop for (unsigned short a = 0; a < moreGradesToCalculate.length(); a++) { moreGradesToCalculate[a] = toupper (moreGradesToCalculate[a]); } //end of for loop } //end of while loop cout<< "Thanks for using the Grades Calculation program! "; return 0; } //end of main
It seems that this part of codes here has the error:
Thanks in advance!Code://start of while loop while (moreGradesToCalculate == "YES") { //promting user for the type of students to calculate cout<< "*** 1) English, 2) Math, 3) Science *** "; cin.getline (response, 256); if (strlen(response) == 0) { cout<< "You must choose an option"; return 1; //return error }