Help. I don't know how to solve my problem in a program I wrote.

This is a discussion on Help. I don't know how to solve my problem in a program I wrote. within the C Programming forums, part of the General Programming Boards category; Hello to all. I'm sorry but I'm just new at C programming and new to this forum as well. A ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    Help. I don't know how to solve my problem in a program I wrote.

    Hello to all.

    I'm sorry but I'm just new at C programming and new to this forum as well. A friend told me that I could get some good advice regarding C programming here.

    I've written a simple program while practicing the basics of C programming (and I mean BASICS - simple conditionals and scanfs...).

    I'm having a problem with the program I wrote. I was able to compile and run it and it did work. The only problem was it won't wait for the user to type in the gender and the prompting of the user's home adress is a bit messy.

    I was hoping you guys can solve this problem. I'll post in the code I've written. I hope someone can give me some insights on how I can solve this...

    (It's really quite simple actually. I just don't know what went wrong.)

    Thanks.



    I attatched the file named test8.c since I can't post the whole code here...

    Thanks again. More power to this forum.
    Attached Files Attached Files

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    Well, you're asking the user to input their gender, but then you don't actually retrieve it until you've prompted for and retrieved their address.

    One thing that will probably give you problems is that scanf() leaves the trailing \n in the input buffer from when the user pressed ENTER and getchar() will grab that instead of what you're expecting it to grab.

    You might want to use scanf("%c", &gender); instead of using getchar(). Or you can clear the \n off the input buffer before using getchar() to retrieve their gender.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-26-2008, 09:48 AM
  2. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 03:38 PM
  3. Replies: 20
    Last Post: 06-13-2005, 12:53 AM
  4. Problem with Program not Quitting
    By Unregistered in forum Windows Programming
    Replies: 20
    Last Post: 06-12-2002, 12:06 AM

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