I have a program that prompts users to input a grade scored in a particular course e.g "A" and the equivalent of grade "A" is 5. Now, I don't know how to multiply the "A" inputed by the user with another int variable say "50".
This is what I mean:
1 2 3 4 5 6 7 8
string gradescore;
int creditunit;
float GP;
cout<<"Enter your exam grade "; //A, B, C, D, E, or F.
cin>>gradescore;
cout<<"What is the course credit unit? ";
cin>>creditunit; //Maybe 2, 3, 4, etc.
GP = gradescore * creditunit;
But the compiler is quarrying, saying: [Error] no match for'operator*'
#include <iostream>
usingnamespace std;
int main()
{
char gradescore; //better to use a char than a string
int creditunit;
float GP;
cout<<"Enter your exam grade "; //A, B, C, D, E, or F.
cin>>gradescore;
cout<<"What is the course credit unit? ";
cin>>creditunit; //Maybe 2, 3, 4, etc.
switch (toupper(gradescore)) //converts gradescore to upper (a to A, b to B)
{
case'A':
GP = creditunit * 5; break;
case'B':
GP = creditunit * 4; break;
case'C':
GP = creditunit * 3; break;
case'D':
GP = creditunit * 2; break;
case'E':
GP = creditunit; break;
case'F':
GP = 0; break;
}
cout << "GP: " << GP;
return 0;
}
It's pretty self explanatory, but ask if you have questions. :)
Thanks #Sasauke, the Wisest; for your reply. Just that Advanced Selection, especially the 'Switch_Case' sometimes make me feel dizzy and sleepy that was why I was thinking of something more smarter.
Thanks #Peter; for your reply.
Thanks #Ericool; for your reply but would appreciate better if you explain further...I'm a learner on the wheel.