2 fuctions please

This is a discussion on 2 fuctions please within the C++ Programming forums, part of the General Programming Boards category; hi, could anyone give me examples of 2 fuction please. 1) to force 'enter only numbers' not letters 2) to ...

  1. #1
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147

    2 fuctions please

    hi,
    could anyone give me examples of 2 fuction please.
    1) to force 'enter only numbers' not letters
    2) to force 'enter only letters' not numbers

    thanks.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Code:
    void ENTERANUMBER(int &num) {
        cout << "ENTER A NUMBER AND ONLY A NUMBER!!!!";
        cin >> num;
    }
    void ENTERALETTER(char &let) {
        cout << "ENTER A LETTER AND ONLY A LETTER!!!!";
        cin >> let;
    }
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    alrite if u incorporate a bit of warning in those functions they will work well,like:-
    suppose someone enters a number when he should enter a letter ,the function should give out an error message and should ask him to enter a letter again,this should go on till he enters a letter,now thats a " force letter only " function.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Regardless, he'd have to know how to clear cin after the stream fails.

    Your easiest bet would be to take it in as a character, regardless, compare it's ASCII range to the range that letters are in or numbers are in. If it matches, keep it, if it doesn't, ask again.
    Last edited by SlyMaelstrom; 02-13-2006 at 04:57 AM.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vectors and fuctions
    By mixalissen in forum C++ Programming
    Replies: 13
    Last Post: 05-05-2008, 11:48 AM
  2. Problem with cos, sin fuctions
    By xxxhunter in forum C Programming
    Replies: 7
    Last Post: 11-16-2007, 02:33 AM
  3. Quad equation using fuctions problem
    By godfrey270487 in forum C++ Programming
    Replies: 5
    Last Post: 12-07-2006, 10:23 AM
  4. Need help with fuctions
    By stillwell in forum C++ Programming
    Replies: 13
    Last Post: 01-25-2005, 09:09 AM
  5. Replies: 8
    Last Post: 04-11-2004, 11:19 PM

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