Thread: if your not newb you can help me

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    Exclamation if your not newb you can help me

    i a newb and i need some help that is confusing me. see this code?

    #include <iostream.h>
    int main()
    {
    int thisisanumber;
    cout<<"Please enter a number:";
    cin>>thisisanumber;
    cout<<"You entered: "<<thisisanumber;
    return 0;
    }


    thats from a tutorial from this site. once i eneter a number and press eneter to confirm the window closes. I bielive tha happens because of this line cin>>thisisanumber; what do I press to go to the line cout<<"You entered: "<<thisisanumber;
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    #include <iostream.h>
    int main()
    {
    int thisisanumber;
    cout<<"Please enter a number:";
    cin>>thisisanumber;
    cout<<"You entered: "<<thisisanumber;
    cin>>thisisanumber;
    return 0;
    }

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    how was that helpful you just reposted the code i gave you!
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  4. #4
    Unregistered
    Guest

    Arrow I know

    Your code is fine. What is happening is your program is closing before you have time to see the results... Try putting
    Code:
    getchar();
    just before return 0; and #include <stdio.h>, so your code would be:
    Code:
    #include <iostream.h> 
    int main() 
    { 
    int thisisanumber; 
    cout<<"Please enter a number:"; 
    cin>>thisisanumber; 
    cout<<"You entered: "<<thisisanumber; 
    getchar();
    return 0; 
    }

  5. #5
    >>how was that helpful you just reposted the code i gave you!

    I believe if you look you'll see an additional line in the code Denthor2000 gave back:

    cin>>thisisanumber;

    at the end before the return statement. This will cause your app to pause and wait for input before closing you window, thus giving you time to read. Its one af 100 ways of doing it, but probably the easiest in this situation as it doesnt require any additional headers.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  6. #6
    Unregistered
    Guest

    Oops

    Sorry, that would be:
    Code:
    #include <stdio.h>       // I forgot to mention this, :D
    #include <iostream.h> 
    int main() 
    { 
    int thisisanumber; 
    cout<<"Please enter a number:"; 
    cin>>thisisanumber; 
    cout<<"You entered: "<<thisisanumber; 
    return 0; 
    }

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Originally posted by Klinerr1
    how was that helpful you just reposted the code i gave you!
    actually, look again. try compiling it before you post. If you looked closely you would see the difference, look:

    you posted:
    Code:
    #include <iostream.h> 
    int main() 
    { 
    int thisisanumber; 
    cout<<"Please enter a number:"; 
    cin>>thisisanumber; 
    cout<<"You entered: "<<thisisanumber; 
    return 0; 
    }
    i posted:
    Code:
    #include <iostream.h> 
    int main() 
    { 
    int thisisanumber; 
    cout<<"Please enter a number:"; 
    cin>>thisisanumber; 
    cout<<"You entered: "<<thisisanumber; 
    cin>>thisisanumber; 
    return 0; 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  2. Dogpile the newb!
    By lindy in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 05-23-2008, 08:17 AM
  3. Total newb directx invisable geometry question
    By -pete- in forum Game Programming
    Replies: 5
    Last Post: 08-13-2006, 01:45 PM
  4. Newb C++ Programmer
    By Philandrew in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2004, 08:44 PM
  5. Newb With Small Pointer Issue
    By G-Prime in forum C Programming
    Replies: 7
    Last Post: 09-06-2004, 04:09 PM