quicky

This is a discussion on quicky within the C Programming forums, part of the General Programming Boards category; while((a[i].sex != '0') && (a[i].sex != '1')) { printf("Error, please may you enter 1 for male or 0 for female(person ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    18

    Talking quicky

    while((a[i].sex != '0') && (a[i].sex != '1'))
    {
    printf("Error, please may you enter 1 for male or 0 for female(person %d)\n", i);
    scanf("%d",&a[i].sex);
    }

    why does this not work if someone enters in 1 / 0 for a[i].sex

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    18
    sorry ignore I am a dumb git made a typo

  3. #3
    Unregistered
    Guest
    while((a[i].sex != '0') && (a[i].sex != '1'))

    That won't work because you're using the characters 0 and 1, which are completely different in integer value from the integers 0 and 1.

    while( ( a[i].sex != 0 ) && ( a[i].sex != 1) ) {

    -Prelude

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a quicky C reference guide of come sort
    By iecki in forum C Programming
    Replies: 2
    Last Post: 01-17-2008, 06:42 PM
  2. Quicky Question
    By Krak in forum C++ Programming
    Replies: 8
    Last Post: 02-06-2005, 05:45 AM
  3. quicky
    By CobraCC in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2003, 07:49 PM
  4. stderr quicky question - I GOT IT thank you so much
    By HOWY in forum Linux Programming
    Replies: 0
    Last Post: 07-05-2002, 11:28 AM
  5. stderr quicky question
    By HOWY in forum Linux Programming
    Replies: 1
    Last Post: 07-05-2002, 10:52 AM

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