CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2009
    Posts
    16

    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 ?

  2. #2
    Join Date
    Mar 2008
    Posts
    30

    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.

  3. #3
    Join Date
    Apr 2009
    Posts
    16

    Re: Please check my code....??

    thanks richard but i want to do this by If else only..... can code it by if else ?

  4. #4
    Join Date
    Apr 2009
    Location
    Russia, Nizhny Novgorod
    Posts
    99

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Apr 2009
    Posts
    16

    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
  •  





Click Here to Expand Forum to Full Width

Featured