new to c++ need help

This is a discussion on new to c++ need help within the C++ Programming forums, part of the General Programming Boards category; ok...im new to this c++ stuff and i was wondering why the last prompt wont come up. here is my ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    12

    new to c++ need help

    ok...im new to this c++ stuff and i was wondering why the last prompt wont come up.

    here is my code:

    Code:
     
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main ()
    
    {
        int pounds;       //number of pounds
        int shilling;     //number of shilling
        int pence;        //number of pence
        float decPounds;     //conversion of Decimal Pounds
    
        cout << "Enter number of pounds: ";
        cin >> pounds;
        cout << "Enter number of shilling: "; 
        cin >> shilling;
        cout << "Enter number of pence: ";
        cin >> pence;
    
    decPounds = (shilling * 12 + pence) / 240 + pounds;
    
        cout << "Results in decimal pounds = " ;
        cout << decPounds;
    
        return 0;
        
    }

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    57
    K actually it does show up but it closes right away so just look at what i changed.
    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main ()
    
    {
        int pounds;       //number of pounds
        int shilling;     //number of shilling
        int pence;        //number of pence
        float decPounds;     //conversion of Decimal Pounds
    
        cout << "Enter number of pounds: ";
        cin >> pounds;
        cout << "Enter number of shilling: "; 
        cin >> shilling;
        cout << "Enter number of pence: ";
        cin >> pence;
    
        decPounds = (shilling * 12 + pence) / 240 + pounds;
    
        cout << "Results in decimal pounds = " ;
    *    cout << decPounds<<endl;// look and endl just goes to next line
    *    system("PAUSE");//to stop it for a bit.
    *    //or
    *    //cin.get();// this one teachers like more.
        return 0;
        
    }
    look for * and the coments and you should be fine and remove the *

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Actually just one cin.get() would do nothing but take in the last '\n' and close the program. You also have to add a cin.ignore() after your last cin statement.
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    12
    Everything works fine now. Thanks!

Popular pages Recent additions subscribe to a feed

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