Thread: Need help with loop and switch

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    1

    Need help with loop and switch

    Hi,

    I need help coding a loop with a switch. The outcome I want is when the user inputs a invalid number the menu will loop again allowing the user to input a valid number.

    Can I please have some ideas on how I could do this?Need help with loop and switch-untitled-jpg

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Put it in a do/while loop with the condition being input not being in the range of a correct input
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Apr 2011
    Location
    dust
    Posts
    70
    replace the while with do and put the while at end of switch with a valid condition checking.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    This is for C++, but the loops shown are the same in both languages:
    For, While, and Do While Loops in C++ - Cprogramming.com
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help - Collect data from Switch loop inside While loop
    By James King in forum C Programming
    Replies: 15
    Last Post: 12-02-2012, 10:17 AM
  2. help with a switch and a loop
    By shelcarter in forum C Programming
    Replies: 13
    Last Post: 03-23-2010, 12:13 AM
  3. how to loop in switch??
    By pczafer in forum C++ Programming
    Replies: 6
    Last Post: 05-04-2009, 01:53 AM
  4. Switch in a While Loop
    By WindShield in forum C Programming
    Replies: 6
    Last Post: 10-19-2002, 12:04 AM
  5. can (switch) be apart of a loop?
    By matheo917 in forum C++ Programming
    Replies: 2
    Last Post: 09-20-2001, 06:29 PM