Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- void error()
- {
- using namespace std;
- cout << "An error has occurred... Program exiting..." << endl;
- system("pause");
- }
- int main()
- {
- using namespace std;
- //Declaring doubles and string
- double correct; //points correct
- double possible; //points possible
- double result; //result of correct divided by possible
- string input = ""; //user input
- //Getting student's amount of points correct
- cout << "Enter amount student got correct: ";
- cin >> correct;
- cout << endl;
- //Getting total points possible
- cout << "Enter amount of points possible: ";
- cin >> possible;
- cout << endl;
- //Calculating percentage
- result = correct / possible;
- result = result * 100; //split result into 2 so the order of operations didn't get messed up
- cout << "Percentage: " << result << "%" << endl;
- //Calculating grade
- cout << "Grade: ";
- if (result == 100){
- cout << "5" << endl;
- }else if (result < 100 && result >= 80){
- cout << "4" << endl;
- }else if (result < 79 && result >= 69){
- cout << "3" << endl;
- }else if (result < 68 && result >= 55){
- cout << "2" << endl;
- }else if (result < 54 && result >= 0){
- cout << "1" << endl;
- }
- //Asking user if they would like to exit or not
- cout << endl << "Would you like to exit, or grade another student?\n";
- cout << "To exit, type \"exit\"" << endl;
- cout << "To grade another student, type \"new\"" << endl;
- cout << endl;
- cin >> input;
- if (input=="exit"){ //if user typed exit, then exit
- exit(0); //exit returning 0 meaning program didn't encounter errors
- }else if (input=="new"){ //if user typed new, then go back to the start of main
- system("cls"); //clear the window
- main(); //go back to the beginning
- }else{
- error();//error
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement