Grading PRogram

I'm having trouble, I don't know how to exit main and end the program if the user is exempt the first time. Also I have to make the program determine the best grade they can obtain after taking the final(worth 100 points) if they are not exempt after the first two times being asked.

Grading Ranges are
A = 450 – 500
B = 400 – 449
C = 350 – 399
D = 300 – 349

F = 0 – 299


#include <iostream>
#include <cmath>
#include<iomanip>
using namespace std;

struct FinalGrade
{
double hw1;
double hw2;
double hw3;
double hw4;
double hw5;
double hw6;
double hw7;
double quiz1;
double quiz2;
double quiz3;
double test1;
double test2;
double ec1;
double ec2;
double ec3;
double ec4;
double ec5;
double final;
double finalgrade;
};

int main() {
FinalGrade Sean;
double score = 0.0;

cout << "This program will calculate your final grade for the semester" << endl;

cout << "Enter your grade for Homework 1(Range from 0-20): " << endl;
cin >> Sean.hw1;

cout << "Enter your grade for Homework 2(Range from 0-30): " << endl;
cin >> Sean.hw2;

cout << "Enter your grade for Homework 3(Range from 0-30): " << endl;
cin >> Sean.hw3;

cout << "Enter your grade for Homework 4(Range from 0-30): " << endl;
cin >> Sean.hw4;

cout << "Enter your grade for Homework 5(Range from 0-30): " << endl;
cin >> Sean.hw5;

cout << "Enter your grade for Homework 6(Range from 0-30): " << endl;
cin >> Sean.hw6;

cout << "Enter your grade for Quiz 1(Range from 0-20): " << endl;
cin >> Sean.quiz1;

cout << "Enter your grade for Quiz 2(Range from 0-20): " << endl;
cin >> Sean.quiz2;

cout << "Enter your grade for Quiz 3(Range from 0-20): " << endl;
cin >> Sean.quiz3;

cout << "Enter your grade for Test 1(Range from 0-70): " << endl;
cin >> Sean.test1;

cout << "Enter your grade for Test 2(Range from 0-70): " << endl;
cin >> Sean.test2;

cout << "Enter your grade for Extra Credit Assigment 1(Range from 0-20): " << endl;
cin >> Sean.ec1;

cout << "Enter your grade for Extra Credit Assigment 2(Range from 0-20): " << endl;
cin >> Sean.ec2;

cout << "Enter your grade for Extra Credit Assigment 3(Range from 0-20): " << endl;
cin >> Sean.ec3;

cout << "Enter your grade for Extra Credit Assigment 4(Range from 0-20): " << endl;
cin >> Sean.ec4;

cout << "Enter your grade for Extra Credit Assigment 5(Range from 0-20): " << endl;
cin >> Sean.ec5;

score += Sean.hw1 + Sean.hw2 + Sean.hw3 + Sean.hw4 + Sean.hw5 + Sean.hw6 + Sean.quiz1 + Sean.quiz2 + Sean.quiz3 + Sean.test1 + Sean.test2 + Sean.ec1 + Sean.ec2 + Sean.ec3 + Sean.ec4 + Sean.ec5;

cout << "Your total score is " << score << endl;

if(score == 450 || score > 450)
cout << "You are exempt from the Final Exam" << endl;

else
cout<< "You are not exempt" << endl;

cout<< "Enter your projected grade for Homework 7: " << endl;
cin >> Sean.hw7;
score += Sean.hw7;

if(score == 450 || score > 450)
cout << "You are exempt from the Final Exam" << endl;

else
cout<< "You are still not exempt" << endl;

std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
}
Last edited on
Exit the program with return 0;

You can put that in a if statement ... ie.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (condition)
{
   //Exit program
   return 0;
}
else if (condition)
{
  //do something else
}
else
{
  //do something else
}

etc...

Also, just a suggestion... why don't you use arrays and loops to do this program? You are going about it the hard way.
Last edited on
Will I still be able to use the " if(score == 450 || score > 450) " statement in the "else if " part? if so how? and I'm just going about it the way I understand the most right now. It's more simpler to me
yes. but why not just write it as..

1
2
3
4
5
6
7

//If score is greater than or equal to 450...
if (score >= 450) 
{
  return 0; //Exit program
}


if you want to make it easier to read....
 
if (score >= 450) return 0;


Nestled, it would be something like...

1
2
3
4
5
6
7
8
9
10
11
12
if (condition)
{
  //do this
}
else if (score >= 450)
{
  return 0;
}
else
{
  //do this
}
Last edited on
Still need help someone please...these answers weren't very helpful to my question.
If the student is exempt from the exam, I just want the program to end right there..but it still asks to input the projected grade for hw7
I tried return 0; but it still continues
Without rewriting the entire code, which could greatly be improved upon, here is a simple way of making it achieve what you want:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Snip...
if(score >= 450)
   cout << "You are exempt from the Final Exam" << endl;

else {
   cout<< "You are not exempt" << endl;

   cout<< "Enter your projected grade for Homework 7: " << endl;
   cin >> Sean.hw7;
   score += Sean.hw7;

   if(score >= 450)
      cout << "You are exempt from the Final Exam" << endl;

   else 
      cout<< "You are still not exempt" << endl;
}
std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
}
@Volatile Pulse, just tried that and it still continues through the program even though exempt >__<
Can you post the output of your program? I'm not sure we're on the same page as to what continuing through your program means. Logically, after you display your score, if it's over 450, it'll say you're exempt, display "Press ENTER to continue..." and wait for you to press a button. Otherwise, it will move on. Just make sure you're putting it in the correct place.
My output is:

Your total score is 470.
You are exempt from the Final Exam
Enter your projected grade for Homework 7: 30
You are exempt from the final exam
Press ENTER to continue...press any key to continue
your testing against int's. you need to add .0 on the end to the conditions
Topic archived. No new replies allowed.