Im new to C++ and im stuck on this program. Ive done some of it but im having problems knowing how to add the "Y or N extra credit points"..Can someone please give me some pointers on how to do it.. Ive thought of using a switch statement for the Y or N but dont know how to combine it to the whole program...
This is the assignment.
Write a program to prompt the user to enter a grade between 0 and 100.
If the grade is not between 0 and 100 display an error message Display the proper letter grade based on the number entered (A,B,C, D, F)
Before determining the letter grade, do the following:. o After entering the grade ask, the user if the grade is eligible for extra credit.
o If the user enters y or Y add 5 points the grade entered
o It the user enters n or N leave the grade alone
o If they enter any other letter subtract 10 points for not following instructions
#include <iostream>
using namespace std;
int main()
{
float grade;
char letter;
cout << "Please enter a grade between 0 and 100: ";
cin >> grade;
if ( grade >= 100.0 )
{
cout << "Error not between 1-100.";
}
else if ( grade >= 90.0 )
{
letter = 'A';
}
else if ( grade >= 80.0 )
{
letter = 'B';
}
else if ( grade >= 70.0 )
{
letter = 'C';
}
else if ( grade >= 60.0 )
{
letter = 'D';
}
else
{
letter = 'F';
}
cout << "Your Grade is " << letter << "\n\n";
I like the part with "subtract 10 points for not following instructions". That'll teach them! :-D
Anyway, if you came that far with your code, you shouldn't have problems with the rest.. :) Just read in the y/n question into a variable like you did with grade and use the same kind of if/else if/else construction you used before.