Thread: read roll no., marks, count pass and fail

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    read roll no., marks, count pass and fail

    Hi

    I was trying to write a code to read roll no., marks, count pass, fail, A grade, B grade, etc. Do you find the code okay? As far as I could confirm it was working fine. I wanted your advice on those bold red braces which I want to use for clarification to show that the statements within those red braces are related. Can those red braces affect the the overall working? Please let me know. Thanks

    Regards
    Jackson

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    
    {
      int rollno=0, pass=0, fail=0, Agrade=0, Bgrade=0, Cgrade=0, Dgrade=0, Egrade=0, Fgrade=0;
      float TM=0, OM=0;
    
      cout << "Enter total marks: ";
      cin >> TM;
    
      do
        {
            cout << "Enter Roll No. : ";
            cin >> rollno;
    
            cout << "Enter obtained marks: ";
            cin >> OM;
    
            {
            if (OM >= 0.5*TM)
                {
                    pass = pass++;
                }
            else
                {
                    fail = fail++;
                }
            }
    
            {
            if (OM >= 0.8*TM)
                {
                    Agrade = Agrade++;
                }
    
            else if (OM >= 0.7*TM)
                {
                    Bgrade = Bgrade++;
                }
    
            else if (OM >= 0.6*TM)
                {
                    Cgrade = Cgrade++;
                }
    
            else if (OM >= 0.5*TM)
                {
                    Dgrade = Dgrade++;
                }
    
            else if (OM >= 0.4*TM)
                {
                    Egrade = Egrade++;
                }
    
            else
                {
                    Fgrade = Fgrade++;
                }
            }
    
        }
    
        while (rollno > 0);
    
      cout << "Total pass is: " << pass << endl;
      cout << "Total fail is: " << fail << endl;
      cout << "Total A grades are: " << Agrade << endl;
      cout << "Total B grades are: " << Bgrade << endl;
      cout << "Total C grades are: " << Cgrade << endl;
      cout << "Total D grades are: " << Dgrade << endl;
      cout << "Total E grades are: " << Egrade << endl;
      cout << "Total F grades are: " << Fgrade << endl;
    
      system("pause");
    
    }
    Last edited by jackson6612; 04-23-2011 at 04:33 PM.
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    They're not harmful in any way if that's what you're asking.

    > I want to use for clarification to show that the statements within those red braces are related.
    I would normally use a blank line and a comment to achieve the same thing.
    Code:
            // calculate overall pass/fail
            if (OM >= 0.5*TM)
                {
                    pass++;
                }
            else
                {
                    fail++;
                }
    
            // calculate individual grades
            if (OM >= 0.8*TM)
    > pass = pass++;
    But all the statements like this are wrong, it's just
    pass++;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 10-16-2009, 07:02 PM
  2. Roll on 18 wheels roll on
    By abachler in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 05-13-2009, 09:12 PM
  3. count how many lines, allocate vector, and read again
    By patiobarbecue in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2009, 07:18 PM
  4. fail to count digit of an integer (fail at 9)
    By azsquall in forum C++ Programming
    Replies: 3
    Last Post: 05-02-2008, 09:42 AM
  5. Grade program, pass/fail
    By jadedreality in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2007, 03:58 AM