Thread: make user press enter / wierd code thingy

  1. #1
    Registered User CorvusVita's Avatar
    Join Date
    Apr 2006
    Location
    Yorkshire
    Posts
    5

    make user press enter / wierd code thingy

    hello,

    yesterday, i thought i'd have a "bash" at programming. so here i am.
    after reading some tutorials - i thought i'd have a go myself, after some problems with flashing screens .ect (which i fixed by searching the forums) i'm now stuck.

    what i would like help with, if you would be so kind, is:

    i would like to make the user hit the enter key, before the next line is printed/displayed - as it all comes at once

    i would also like to know why, when i run my little ditty, it give me a wierd little code thing
    OK richie0x4433c4AKA CorvusVita
    even though I'm not getting an error code in DEV-C++

    heres the code - its pretty simple stuff

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char thisisaname[20];       //dont forget the [20] bit idiot
        char secondname[20];
    
        cout<<"What is your name? ";
        cin>> thisisaname;
        cout<<"Hello "<< thisisaname <<"\n";
        cout<<"Right that's about it for now"<<"\n";
        cout<<"OH! befor you go..."<<"\n";
        cout<<"what's your forum tag?";
        cin>> secondname;
        cin.ignore();
        cout<<"OK "<< thisisaname << cout<<"AKA "<< secondname <<"\n";
        cout<<"I'll see you in the forums";
        cin.get();
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i would like to make the user hit the enter key, before the next line is printed/displayed - as it all comes at once
    Doesnt that already happen?

    The second cout here is rather out of place:
    Code:
    cout<<"OK "<< thisisaname << cout<<"AKA "<< secondname <<"\n";
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Should something not be returned?

  4. #4
    Registered User CorvusVita's Avatar
    Join Date
    Apr 2006
    Location
    Yorkshire
    Posts
    5
    Quote Originally Posted by laserlight
    Doesnt that already happen?
    no it just bangs all the information up at once
    i mean all this come up at once
    Code:
        cout<<"Right that's about it for now"<<"\n";
        cout<<"OH! befor you go..."<<"\n";
        cout<<"what's your forum tag?";
    The second cout here is rather out of place:
    Code:
    cout<<"OK "<< thisisaname << cout<<"AKA "<< secondname <<"\n";
    do you mean the space between
    << and cout

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, I mean the cout itself. You should just write:
    Code:
    cout << "OK " << thisisaname << "AKA " << secondname << "\n";
    Should something not be returned?
    The global main() function returns 0 if no return statement is encountered by the time control reaches its end.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    You don't need the cout at all there.

    As LaserLight says...it should be getting user input on the same line like you want.

    Edit::looks like you got there before me!

  7. #7
    Registered User CorvusVita's Avatar
    Join Date
    Apr 2006
    Location
    Yorkshire
    Posts
    5
    thanks guys that sorted out the wierd code bit. silly me.

    but i can t figure the enter thing

    I'm new and i'm sticking to that excuse

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    but i can t figure the enter thing
    Consider using cin.ignore().
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Maybe if you print your screen and upload it to imageshack.

  10. #10
    Registered User CorvusVita's Avatar
    Join Date
    Apr 2006
    Location
    Yorkshire
    Posts
    5
    ahhhh....

    thanks very much, i did have cin.ignore on one line earlier - butit didnt "seem" to do anything so i took it out.

    works perfectly now.
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char thisisaname[20];       //dont forget the [20] bit idiot
        char secondname[20];
    
        cout<<"What is your name? ";
        cin.ignore();
        cin>> thisisaname;
        cin.ignore();
        cout<<"Hello "<< thisisaname <<"\n";
        cin.ignore();
        cout<<"Right that's about it for now"<<"\n";
        cin.ignore();
        cout<<"OH! before you go..."<<"\n";
        cin.ignore();
        cout<<"what's your forum tag?";
        cin.ignore();
        cin>> secondname;
        cin.ignore();
        cout<<"OK "<< thisisaname << " AKA "<< secondname <<"\n";
        cin.ignore();
        cout<<"I'll see you in the forums";
        cin.get();
    }
    thanks again LaserLight
    and Bumfluff also

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I didnt actually do anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C programing
    By flame82 in forum C Programming
    Replies: 2
    Last Post: 05-07-2008, 02:35 PM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. Assignment output help
    By Taka in forum C Programming
    Replies: 13
    Last Post: 09-23-2006, 11:40 PM
  4. user can hit enter all day long
    By Ash1981 in forum C Programming
    Replies: 7
    Last Post: 01-01-2006, 05:33 AM
  5. terminate 0 - PLEASE HELP
    By Unregistered in forum C Programming
    Replies: 11
    Last Post: 11-21-2001, 07:30 AM