inputs limiting and conversion in C Programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • razoul
    New Member
    • May 2010
    • 1

    #1

    inputs limiting and conversion in C Programming

    how to limit inputs in c programming

    for example limit number of inputs being taken from the user
    Last edited by razoul; May 27 '10, 02:38 AM. Reason: nothing
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    In the simplest sense you prompt a user with a cout<< or printf() statement and then provide the user with a scanf() or cin>> statement which will take her input.
    You can use an if statement or try, throw and catch statements to control what will be accepted as input.e.g.:
    Code:
    cout<<"state your age";cin>>age;if(age<5||age >105)
    cout<<"are you sure";

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      You can't actually limit what the user types into stdin (the console) all you can do is read what is input and if it is not correct display and error and request the input again.

      Comment

      Working...