#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
int iscore;
double dscore;
iscore=dscore;
cout << " \n\n\t\tPlease enter your score: ";
cin >> iscore;
cout << setprecision(2) << fixed; // We set setprecision value to 0 to round it to an integer (>= .5 rounds up, <.5 rounds down.)
switch (iscore)
{ // Beginning of switch.
case 100:
case 99:
case 98:
case 97:
case 96:
case 95:
case 94:
case 93:
case 92:
case 91:
case 90: cout << " \n\n\t\tYou Are Smart! \n \n\t\tPercentage : " << iscore <<"% Grade A Points: 4.0 " ; break;
case 89:
case 88:
case 87:
case 86:
case 85:
case 84:
case 83:
case 82:
case 81:
case 80:cout << " \n\n\t\tWow! That is very good! \n \n\t\tPercentage : " << iscore <<"% Grade B Points: 3.0 " ; break;
case 79:
case 78:
case 77:
case 76:
case 75:
case 74:
case 73:
case 72:
case 71:
case 70:cout << " \n\n\t\tYou can do better! \n \n\t\tPercentage : " << iscore <<"% Grade C Points: 2.0 " ; break;
case 69:
case 68:
case 67:
case 66:
case 65:
case 64:
case 63:
case 62:
case 61:
case 60:cout << " \n\n\t\tYou Are Not Smart! \n \n\t\tPercentage : " << iscore <<"% Grade D Points: 1.0 " ; break;
default:
cout << " \t\t\t You have failed ! ";
} // end of switch.
return 0;
}
omg do you really think thats the right way to go about making a switch statement with all those cases?
Could you imagine if that was the only way to do what you did? A larger more complex project would be.....I can't even fathom how hard it would be to program...
Use an if statement if a grade is between 90 and 100 cout << "ablabalhba" << endl;
Here is a simplified grading system.
Grade Points Percentage
A 4.00 90-100
B 3.00 80-89
C 2.00 70-79
D 1.00 60-69
F 0.00 <60
Write a C++ program that:
• asks for and accepts the Percentage earned with as a double (i.e. 75.45)
• rounds it to an integer (>= .5 rounds up, <.5 rounds down.)
• prints the original Percentage and the corresponding Grade and Points exactly as shown below.
• prints an error message for any input that is less than 0 or greater than 100.
For example, if user enters 89.4, the program prints out:
Percentage: 89.4% Grade: B Points: 3.00
2) Rounding: don't know if you are confused on this but here is my explanation
When you convert a double to an integer..you loose all the data to the right of the decimal point...this is called truncation. So if you have a double of 5.9 and casted that to an int you would have 5. You have to program the "algorithm" basically tell the computer how to round. Remember..When programming you have to tell the computer every step!
Any number that has X.5 or greater will round up after adding 0.5, and any number that is less than X.5 will be rounded down. This is what you do in your head without even realizing it.
EXAMPLE:
So for your program if the grade is 89.58 and you add 0.5 to it it becomes 90 if you cast that to an int...But if you casted that to an int before adding the 0.5 it would be 89..It would have not rounded up! Now you are thinking why adding 0.5? Well this is explicating telling the computer how to round! The computer has no conceptional understanding of what rounding is....or anything at all for that matter it only knows what you tell it...
If you were to add 0.5 to 89.48 this would not round up to 90...Casted to an int you would get 89...
So Formula for rounding is intGrade = doubleGrade + 0.5;