Hit Enter, Return mainscr();

This is a discussion on Hit Enter, Return mainscr(); within the C++ Programming forums, part of the General Programming Boards category; I'm making a program and I need to know how to, on enter, return my mainscr(); function. Like, after they ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    193

    Hit Enter, Return mainscr();

    I'm making a program and I need to know how to, on enter, return my mainscr(); function. Like, after they finish reading the instructions, I want them to be able to hit Enter and have it return my mainscr(); function. I've tried:

    Code:
    cin.get();
    mainscr();
    But that returns mainscr(); before they hit Enter. Also, I made a betting program and every time it calls a new function, it clears the screen, but in the one I'm doing now, every time it calls a new function it doesn't clear the screen which is irretating me because I have to add: system ("cls"); to the beginning of every function. If it helps at all, I'm using Dev-C++ 4.0 to compile these programs.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Try:

    cin >> variableOfYourChoice;

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Thanks for the info. It works, but now my only complaint is that when Enter is hit, it just drops down a line so they have to enter in a character or an integer then hit enter, but at least it works. Thanks again.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Try adding:
    Code:
    std::cin.ignore(std::numeric_limits<std::streamsize>max(),'\n');
    Before your call to std::cin.get()

    Edit: Actually, I think std::cin.ignore() will work as well...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    EDIT: cin.ignore(); works perfect. Thanks very much for all of your help.
    Last edited by stickman; 08-23-2004 at 10:10 PM.

  6. #6
    C++ n00bie :D
    Join Date
    Jul 2004
    Posts
    63
    Heres something:
    Code:
    if(getch()!='\0') mainscr();
    That should return mainscr() each time any key is hit, if not, just try playing with it...

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Quote Originally Posted by LloydUzari
    Heres something:
    Code:
    if(getch()!='\0') mainscr();
    That should return mainscr() each time any key is hit, if not, just try playing with it...
    Thanks for the code, but I don't think I'll use it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 06:03 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 11:00 PM
  4. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 12:29 PM
  5. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM

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