Thread: Neeh Help in C++ Programming

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Lightbulb Neeh Help in C++ Programming

    Hi everybody,

    I need a little help in my university assignment of C++ Programming.
    I have to make a programme which should takes 10 inputs of grades and will count the total no of 'A' grades and 'B' grades and shows the result.
    Inputs would be taken as character 'A' and 'B' only and using while or do/while loop.
    This is my code.

    Code:
    /*tnos = total no of students
       grad = grades
       ga = total of grades a
       gb = total of grades b*/
    
    #include <iostream.h>
    using namespace std;
    int main()
    {
          char grad;
          int tnos, ga, gb;
          tnos = 1;
          ga = 0;
          gb = 0;
          do
          {
                     cout<<"Enter the Grade of Student "<<tnos<<" :";
                     cin>>grad;
                     if(grad=='a')
                     {
                             ga=ga+1;
                             tnos=tnos+1;
                             }
                     else if(grad=='b')
                     {
                                  gb=gb+1;
                                  tnos=tnos+1;
                                  }
                     else
                     {
                         cout<<"Please enter only gra A or B:";
                         }
                         }
                         while(tnos<=10):
                         {
                                         cout<<"Total A grades are : "<<ga;
                                         }                  
                     }
    but my code is worked till loop and end after it. i.e. it gets the codes right but did not shows any result and close the cmd windows.

    Please help me urgently today is the last date od submission. I found this forum after a long search so please help.

    Thanx to all

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Do you get any error/warning messages when you compile this code?

    If so please provide the entire error message.

    What compiler are you using?

    You need to do a web search on indentation styles and then pick and use that indentation style.

    In the following code:

    Code:
       while(tnos<=10):
    The colon on the end of the while should be a semicolon. (your compiler should complain about this).

    Also which block of code does this while belong to, the code preceding the while or the code after the while?

    Also you should use more descriptive variable names. A meaningful name will help in your debugging phase of program development.

    Jim

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Alaska
    Posts
    3
    It sounds like you need to pause the program at the end to me.

    Code:
    #include <cstdlib.h>
    
    int main()
    {
    system("PAUSE");
    }
    This program would say 'Press any key to continue...' at the bottom of the screen. So just do the include at the beginning, and insert the system("PAUSE") at the end after you output the data.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Such a thing is not necessary, is non-standard, a security risk and ugly.
    I would suggest reading SourceForge.net: Pause console - cpwiki
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Tags for this Thread