where have i gone wrong?

This is a discussion on where have i gone wrong? within the C Programming forums, part of the General Programming Boards category; Can someone please tell me what is wrong with this code, and how i should fix it. if (waether == ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    51

    where have i gone wrong?

    Can someone please tell me what is wrong with this code, and how i should fix it.

    if (waether == sunny)
    if (day == saturday)
    printf("go to the beach\n");
    else
    print("take your umbrella\n");

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    There's a lot wrong with it, if saturday and sunny aren't variables. also, there's no "print" function - you want printf.

  3. #3
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    hmm

    The logic doesn't look very good, anyway, is this what you
    wanted to do ?
    Code:
    if ((weather==sunny) && (day==saturday))
    {
          printf("Go to the beach\n");
    }
    else
    {
          printf("Take your umbrella\n");
    }

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Can someone please tell me what is wrong with this code, and how i should fix it.
    Make sure that your variables are all declared and spelled correctly, then change print to printf and place brackets around the first two if statements. An else will bind with the closest if, so your logic actually runs like this:
    Code:
    if ( weather == sunny ) {
      if (day == saturday)
        printf("go to the beach\n");
      else
        printf("take your umbrella\n");
    }
    Judging from the messages, you want this to happen instead:
    Code:
    if ( weather == sunny ) {
      if (day == saturday)
        printf("go to the beach\n");
    }
    else
      printf("take your umbrella\n");
    Otherwise you would take your umbrella when it's sunny on every day but Saturday.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

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