Return to main menu after invalid choice

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 2019 Views - Last Post: 04 August 2012 - 07:46 PM Rate Topic: -----

#16 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1922
  • Posts: 5,731
  • Joined: 05-May 12

Re: Return to main menu after invalid choice

Posted 04 August 2012 - 06:45 PM

The system("pause") at line 32 may have something to do with that. Happens when you press a key?
Was This Post Helpful? 0
  • +
  • -

#17 trilly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-July 12

Re: Return to main menu after invalid choice

Posted 04 August 2012 - 06:47 PM

With the system pause, when you hit a key the invalid entry just comes up again. Without the system pause, the screen just flashes back and forth between the menu and invalid entry screen without enough time to even read what it says
Was This Post Helpful? 0
  • +
  • -

#18 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1922
  • Posts: 5,731
  • Joined: 05-May 12

Re: Return to main menu after invalid choice

Posted 04 August 2012 - 07:30 PM

Try putting:
cin.ignore(1000, '\n');


in the else clause.
Was This Post Helpful? 0
  • +
  • -

#19 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 979
  • View blog
  • Posts: 3,397
  • Joined: 19-February 09

Re: Return to main menu after invalid choice

Posted 04 August 2012 - 07:46 PM

The variable selection is an int. When you attempt to enter a character the cin stream will fail. Subsequent cin calls will skip due to the stream being in a fail state.

    cin >> selection;



You could use the clear function before the next read.

    cin.clear();
    menu(selection);




Another option would be to use a character type for the selection variable.

This post has been edited by #define: 04 August 2012 - 07:46 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2