Ok, so I am writing a program that states your grade + GPA after you enter a grade and the course level. Using switches and if/else to do this, or trying. The GPA scale is as follows:
Grade . Reg . Hon . AP
97- 100 4.0 . 4.5 . 5.0
94-96 . 3.7 . 4.2 . 4.5
91-93 . 3.5 . 4.0 . 4.5
87-90 . 3.3 . 3.8 . 4.5
84-86 . 3.0 . 3.5 . 4.0
81-83 . 2.7 . 3.2 . 3.7
77-80 . 2.3 . 2.8 . 3.3
75-76 . 2.0 . 2.5 . 3.0
70-74 . 1.0 . 1.5 . 1.9
So to accomplish this so far I have
Code:
#include <iostream.h>
void main()
{
int grade, level;
cout<< "What is your grade?";
cin>> grade;
cout<< "What type of class is it?\n1.) Regular\n2.) Honors\n3.) AP";
cin>> level;
int c=(grade>=97)+(grade>=94)+(grade>=91)+(grade>=87)+(grade>=84)+(grade>=81)+(grade>=77)+(grade>=75)+(grade>=70);
if(level == 1)
{
switch(c)
case 1:
cout << grade << " C "<<showpoint<<1.0<<endl;
As you can tell the code is not finished, and I plan to switch on c with 12 cases that represent all 12 GPAs for each level of classes. I think this will work, but is there any way to shorten the code that I am not seeing using the same structure? I am pretty new to programming, and any help or suggestions would be appreciated. Thanks