Please check my code....??
Code:
#include <iostream.h>
int main()
{
int grade;
cout<<"Please enter obtained marks: ";
cin>>grade;
if (grade >= 90)
cout<<"Your Grade is: 'A'\n";
else if (grade >=80)
cout<<"Your Grade is: 'B'\n";
else if (grade >=70)
cout<<"Your Grade is: 'C'\n";
else if (grade >= 0)
cout<<"Please increase your numbers for attractive grade. Thanks!\n";
system ("pause");
}
This grading code to show the grade according to abtaining marks. but it ends up when it complete first output like when i entered marks one time it shows its relevant grade and then it terminates but i want it to keep continue to get other marks.? how to do that ?
Re: Please check my code....??
Include iostream; not iostream.h. Indent the bodies of your if and else if statements properly or you may want to use the switch statement. To continue getting other marks, use the while or do..while loop.
Code:
char input ='\0';
bool quit = false;
do {
std::cout << "Enter q to quit";
std::cin >> input;
if(input=='q') {quit =true;}
else {std::cout << "Invalid input!";}
}while(!quit);
Re: Please check my code....??
thanks richard but i want to do this by If else only..... can code it by if else ?
Re: Please check my code....??
No, you can't organize the loop with if..else statements. You should choose one of the reiterated statements: for(;condition;), do..while(condition), while(condition) or you can do this by the recursion
Re: Please check my code....??
I agree with ixSci: use a loop. You can do it with an if statement in conjunction with a label and goto, but that would be rather pointless in a language like C++ that provides loop constructs.
Re: Please check my code....??
thanks....let me try with for loop...........