-
April 12th, 2009, 04:27 AM
#1
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 ?
-
April 12th, 2009, 04:45 AM
#2
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);
Last edited by richard_tominez; April 12th, 2009 at 05:05 AM.
-
April 12th, 2009, 05:51 AM
#3
Re: Please check my code....??
thanks richard but i want to do this by If else only..... can code it by if else ?
-
April 12th, 2009, 06:34 AM
#4
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
-
April 12th, 2009, 02:20 PM
#5
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.
-
April 12th, 2009, 02:57 PM
#6
Re: Please check my code....??
thanks....let me try with for loop...........
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|