Hi, (I am one hell of a newbie in C++)
The Question is:
Write a C++ program that prompt user to enter obtained(0 - 100) marks for five course. Calculate grade for each course using Switch Expression. Display the grade for each course on new line.
i came up with this code... and its not working.. (but when it does, it only shows the grade for the last subject. But the question is asking grades for each subject)
any help.? Please ?
Sorry, if there are mistakes in my coding.
#include<iostream>
using namespace std;
int main()
{
int Marks;
char grade;
cout<<"Enter the obtained marks :"<<endl<<endl;
cout<<"English : ";
cin>>Marks;
cout<<"Programming : ";
cin>>Marks;
cout<<"Calculus : ";
cin>>Marks;
cout<<"Electronics : ";
cin>>Marks;
cout<<"Statistics : ";
cin>>Marks;
You should put your code [code]between code tags[/code] so that it has proper syntax highlighting and line numbers. There was a template for you when you started the topic but you seem to have deleted it.
The reason your code only processes the last grade is because you overwrite the previous grades without doing anything with them. Don't use copy-and-paste to fix this, by the way (if you don't know what I mean, that's good). I would recommend using a function and calling the function to decide the letter grade after each input.
Your switch statement is "clever" but not the ideal way to process the grades - it's better to use if-else-if statements with the > operator. What if a student gets a bonus 10 points on a grade? With your current code, they fail the class for going the extra mile.