steamengines

Percent grades. (arrays)

Nov 11th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. //Christian Ballard
  2. //COSC 1330 - 003
  3. //This program should calculate and dislplay a student's letter grade.
  4. #include <iostream>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     char letterGrades[5] = { 'A', 'B', 'C', 'D','F' };//Inputs!!!
  11.     int letterGradeNumbers[5] = { 90, 80, 70, 60, 0 };
  12.     double possiblePoints = 0.0;
  13.     double pointsRecieved = 0.0;
  14.     double percentGrade = 0.0;
  15.     char updateRead = ' ';
  16.     cout << fixed << setprecision(1);//I decided to show the percent grade and didn't want the decimal to run on.
  17.  
  18.     do//The loop that loops the entire program.
  19.     {
  20.         system("cls");//Clearing the screen.
  21.         cout << "Please enter how many points are possible to recieve." << endl;//Getting some inputs.
  22.         cin >> possiblePoints;
  23.         cout << "How many points did you recieve?" << endl;
  24.         cin >> pointsRecieved;
  25.  
  26.         percentGrade = (pointsRecieved / possiblePoints) * 100;//Our calculations.
  27.  
  28.         for (int counter = 0; counter < 5; counter++)//Our second loop that determines the letter grade.
  29.         {
  30.             if (percentGrade >= letterGradeNumbers[counter])//Figuring out what letter to use.
  31.             {
  32.                 cout << "Your percent grade is " << percentGrade << endl;//Displays.
  33.                 cout << "Your letter grade is " << letterGrades[counter] << endl;
  34.                 break;//Breaking us out of the loop.
  35.             }
  36.         }
  37.         updateRead = toupper(updateRead);//Keeping letters uppercase for the update read for the loop.
  38.         cout << "Would you like to calculate another grade? (Y/N)" << endl;//Update read.
  39.         cin >> updateRead;
  40.     } while (updateRead == 'Y'); //End of the loop.
  41.     system("cls");
  42.     if (updateRead = 'N')
  43.         cout << "Goodbye!" << endl;//Exiting.
  44.    
  45.     system("pause");
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment