Results 1 to 6 of 6

Thread: scanf problem

Threaded View

  1. #4
    Junior Member
    Join Date
    Apr 2004
    Location
    United States
    Posts
    24
    As poppy_123 mentioned the C++ syntax is nicer when using cin, unfortunately if you can only use C, then you won't be able to use it.

    I also would mention that IMO using the age array like this makes more sense (replace cin, with your preference of reading user input as needed and cout with your printf command if using strictly C):

    Code:
    int age_count=0;
    int age_needed=3;
    int age[age_needed];
    int age;
    while (age_count < age_needed) {
      cout << "Enter name for user #" << age_count+1 << ": ";
      cin>>age;
      if (age < 18) {
        cout << "Age must be 18+\n";
      }
      else {
        age[age_count]=age;
        age_count++;
      }
    }
    [NOTE] I didn't test the above code, so don't complain if it I made a syntax error
    Last edited by ABS; January 19th, 2011 at 01:16 AM.

Similar Threads

  1. A Headache of an Email Problem
    By AngelicKnight in forum General Computer Discussions
    Replies: 14
    Last Post: June 15th, 2006, 04:04 AM
  2. Serious Problem
    By IcSilk in forum Operating Systems
    Replies: 8
    Last Post: October 30th, 2005, 11:01 PM
  3. 500 mile email problem
    By Tedob1 in forum Tech Humor
    Replies: 0
    Last Post: December 23rd, 2002, 04:58 PM
  4. C problem...
    By Rna in forum General Programming Questions
    Replies: 4
    Last Post: May 22nd, 2002, 07:03 AM
  5. Help! I've got a nasty IDE problem
    By thesecretfire in forum Hardware
    Replies: 16
    Last Post: May 17th, 2002, 12:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •