ImTotallyLOST!

This is a discussion on ImTotallyLOST! within the C++ Programming forums, part of the General Programming Boards category; I_Have_No_Name: First up, have a read of this thread . Now, in answer to your question, when you cin into ...

  1. #16
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I_Have_No_Name: First up, have a read of this thread.

    Now, in answer to your question, when you cin into an int, the newline character is left in the input buffer, so when you do a cin.get at the end, the newline is taken and the program terminates. Here is some revised code that will suit your particular problem (there are many ways, all have which have been discussed on these boards):
    Code:
    #include <iostream.h>
    
    int main(void)
    {
        int age;
    
        cout << "Please input your age: ";
    
        cin >> age;
    
        while (cin.get() != '\n');
        
        if (age < 100)
        {
            cout << "You are pretty young!";
        }
        else if (age == 100)
        {
            cout << "You are old";
        }
        else
        {
            cout << "Are you really that old?";
        }
    
        cin.get();
        
        return(0);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  2. #17
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35

    BRACKET, PARENTHASES ETC...

    Code:
    int main()
    { 
    
    return 0;
    }

  3. #18
    NewBoy
    Guest
    I verly found out that I have Microsoft Visual C++ today.
    So I deleted Borland.
    Im trying to learn C++ whit the tutorials on this website but I have a problem.

    When I open Microsoft Visual C++ This screen comes up whit three blank boxes and some tabs on the top.
    So I click on the FILE tab in the top and click on new.
    Then It has 4 tabs.
    They are Files,Projects,Workspaces, and Other Documents.
    Now I dont know what to do!
    Witch one should I click on?
    I tried clicking on the HELP tab in the top of the MV C++ window to see If it has a help file on how to use the program but when I click on it it says "The MSDN collection does not exist.Plese reinstall MSDN"
    How do I "reinstall" it?

    Please help.

    Thanks in advance.

  4. #19
    NewBoy
    Guest
    Anyone?

  5. #20
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    file/new/(projects tab)win32 console app/type filename/create empty project/finish
    file/new/(file tab) c/c++ source file(.cpp) etc..
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #21
    NewBoy
    Guest
    Thanks.

    And does anyone know if starting whit C++ is a good idea?

Page 2 of 2 FirstFirst 12
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