I need help plz!

This is a discussion on I need help plz! within the C++ Programming forums, part of the General Programming Boards category; Hi. I am a complete newb and need help. I am trying to get this so that if the number ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    2

    I need help plz!

    Hi. I am a complete newb and need help. I am trying to get this so that if the number stored as gendernum is less then or equal to 50 to store girl under the variable gender. And if gendernum is over 50 to store boy under the variable gender. This is the code that I using:
    i
    Code:
    f (gendernum<=50) {
      char gender[5]="girl";
    }
      if (gendernum>50) {
         char gender[5]="boy";
         }
    But when I use the program i get weird charcters displayed instead. What should i do to correct this?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Well if you also have char gender[5] at some outer scope, and you're attempting to assign an array, then it isn't going to work.

    Try
    strcpy( gender, "girl" );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    2

    Talking

    Thanks Salem it worked perfectly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 10:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

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