Runtime error cannot figure out

This is a discussion on Runtime error cannot figure out within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, Following is the C++ code that am stuck with at runtime: Code: #include <iostream> #include <string> using namespace ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    28

    Runtime error cannot figure out

    Hi everyone,

    Following is the C++ code that am stuck with at runtime:

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std ;
    
    
    class gradebook
    
    {
          
          public:
                 
                 void displaymessage (string nameofcourse)
                 
                 {
                      
                      cout << "Welcome to the Gradebook for\n" << nameofcourse ;
                      
                 }
                 
    } ;
    
    
    int main ()
    
    {
        
        string nameofcourse ;
        
        cout << "Please enter the course name\n\n" ;
        
        getline(cin, nameofcourse) ;
        
        cin.get () ;     
        
        gradebook mygradebook ;
        
        mygradebook.displaymessage (nameofcourse) ;
        
        return 0 ;
        
    }
    When I compile(Dev C++ compiler) and run, "Please enter the course name" (without quotes) gets printed however the displaymessage function does NOT get printed. I've deliberately kept the parameter list name to nameofcourse at both places to avoid confusion.

    Please help
    Last edited by exus69; 04-20-2011 at 02:45 AM.

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    remove the cin.get();
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    28
    Removing cin.get () does not help. In fact the screen vanishes if I type something as input and press enter.

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    ...ohh...remove it from that place and put it before "return 0;"
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,935
    Maybe the output would be easier to read if you wrote:
    Code:
    cout << "Welcome to the Gradebook for " << nameofcourse << "\n";
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by exus69 View Post
    Removing cin.get () does not help. In fact the screen vanishes if I type something as input and press enter.
    run your program from command line window
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    28

    Problem solved

    Quote Originally Posted by manasij7479 View Post
    ...ohh...remove it from that place and put it before "return 0;"
    That worked. Thanks alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in runtime
    By sick in forum C Programming
    Replies: 7
    Last Post: 08-15-2009, 02:51 AM
  2. Runtime error
    By MarlonDean in forum C++ Programming
    Replies: 2
    Last Post: 07-02-2008, 02:28 AM
  3. compile time error or runtime error?
    By George2 in forum C# Programming
    Replies: 3
    Last Post: 05-07-2008, 07:08 AM
  4. I'm getting a runtime error
    By Ariod in forum C Programming
    Replies: 6
    Last Post: 02-12-2005, 03:23 PM
  5. Runtime error! Please help
    By Garfield in forum C Programming
    Replies: 7
    Last Post: 09-22-2001, 05:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21