Created
October 30, 2014 01:47
-
-
Save honorelsu/f0c6019aad747e35c55c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| int main() | |
| { | |
| //Moved the variable declarations out of the loop | |
| int main_menu_choice=0; | |
| double homework_grades; | |
| double sum_homework_grades=0; | |
| int count_homework_grades=0; | |
| double sum_quiz_grades=0; | |
| int count_quiz_grades=0; | |
| double test_grades; | |
| string student_name; | |
| //Setup a while loop instead, so that your program could repeat | |
| while (main_menu_choice !=2) | |
| { | |
| cout<< "1 average grades for a new student" << endl; | |
| cout<< "2 to quit\n"; | |
| cin >> main_menu_choice; | |
| if (main_menu_choice ==1) | |
| { | |
| cout<< "Give student name\n"; | |
| cin >> student_name; | |
| cout<< "input homework grades or -1 to end\n"; | |
| cin >> homework_grades; | |
| while (homework_grades != -1) | |
| { | |
| sum_homework_grades = homework_grades + sum_homework_grades; | |
| count_homework_grades= 1 + count_homework_grades; | |
| cin >> homework_grades; | |
| } | |
| double avg_hw=sum_homework_grades/count_homework_grades; | |
| cout<< "the homework average is " << avg_hw << endl; | |
| cout<<"input quiz grades or -1 to end\n"; | |
| double quiz_grades; | |
| cin >> quiz_grades; | |
| while (quiz_grades != -1) | |
| { | |
| sum_quiz_grades= quiz_grades +sum_quiz_grades; | |
| count_quiz_grades= 1+ count_quiz_grades; | |
| cin >> quiz_grades; | |
| } | |
| double avg_quiz= sum_quiz_grades/count_quiz_grades; | |
| cout << "the quiz average is " << avg_quiz << endl; | |
| cout <<"input test grades or -1 to end\n"; | |
| cin >> test_grades; | |
| double sum_test_grades=0; | |
| int count_test_grades=0; | |
| while (test_grades != -1) | |
| { | |
| sum_test_grades= test_grades + sum_test_grades; | |
| count_test_grades= 1 + count_test_grades; | |
| cin >> test_grades; | |
| } | |
| double avg_test= sum_test_grades/count_test_grades; | |
| cout << "the test average is " << avg_quiz << endl; | |
| cout << student_name; | |
| double final_avg=avg_hw*.25 + avg_quiz*.25 + avg_test*.50; | |
| cout << " the final average is " << final_avg << endl; | |
| } | |
| //Added an else condition incase they didn't type 1 for the if | |
| //This gives the user the opportunity to end the program or start over | |
| else | |
| { | |
| cout << "Are you sure you want to quit?\nPlease type 1 to continue or 2 to quit" << endl; | |
| cin >> main_menu_choice; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment