Ask Experts Questions for FREE Help !
Ask
    InfoJunkie4Life's Avatar
    InfoJunkie4Life Posts: 1,409, Reputation: 81
    Ultra Member
     
    #1

    Apr 10, 2013, 01:44 PM
    Why does my C program keep looping?
    I am just starting learning c on my own. I have gone through declaring variables, if/then/else, labels, comments, printf, and scanf functions successfully. I am just learning how to declare and use functions. The program I'm writing is just for practice and means little. It is designed to display some text art on user request and then ask if you want to choose again. I have implemented error correction for choices that are entered incorrectly.

    The code is attached because posting gave me a length error.

    The issue I am having is within the repeat function or within the yorn label. When the program executes it asks "Would you like to choose again (y/n)?"

    No matter what I enter it asks the question again. I originally had else instead of the current if z != and the same results. I have tried y and Y with || and with separate if statements. I cannot seem to solve this issue...

    Thanks in advanced.
    Attached Files
  1. File Type: txt code.txt (15.9 KB, 168 views)
  2. InfoJunkie4Life's Avatar
    InfoJunkie4Life Posts: 1,409, Reputation: 81
    Ultra Member
     
    #2

    Apr 13, 2013, 06:00 PM
    No C programmers on this forum anymore?

    I love it anyway... lol
    InfoJunkie4Life's Avatar
    InfoJunkie4Life Posts: 1,409, Reputation: 81
    Ultra Member
     
    #3

    Apr 22, 2013, 08:15 PM
    Ok, for anyone else who's interested. I decided to go on to my next lesson and continue my program.

    The next lesson was on passing arguments to functions. So I changed the yorn label to parse Boolean the repeat function to parse the text y/n into Boolean. This still achieved the same result.

    So I gave error its own label thinking that would lead me to a more conclusive result, still to no avail. Then I did some digging on the web and found that I was missing else if. I'm used to batch files, when if fails it automatically parses the next statement, in c this is not so; when if fails it will go to the following statement but still pass a fail to the else statement, executing it anyway looping my program.

    Changing all the if's after the first to else if's and using just else instead of if not solved the problem, that and a minor typo in the midst of all this. Included is my new working source.
    Attached Files
  3. File Type: txt source.txt (16.4 KB, 180 views)
  4. cdad's Avatar
    cdad Posts: 12,700, Reputation: 1438
    Internet Research Expert
     
    #4

    Apr 23, 2013, 09:09 AM
    I have to ask. Does the program your using have a debugger built in that you can see line by line what is happening?
    InfoJunkie4Life's Avatar
    InfoJunkie4Life Posts: 1,409, Reputation: 81
    Ultra Member
     
    #5

    Apr 23, 2013, 03:24 PM
    Yes it does, however I did not think to use it. I will try it tonight with both sources, then I'll post back.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Looping Through Sheets [ 1 Answers ]

Is there a way to loop through sheets in a workbook. I would like to add a header/footer to each sheet in a workbook and then apply the header/footer macro to each sheet.

Computer looping [ 7 Answers ]

I am having trouble. We did a complete reinstall on Windows 2000 Professional. It starts the window 2000 set up, but at a certain point,starts allover again loading windows 2000. Ive tried taking the disk out, but it just keeps asking me where to boot from. Here is some of the messages I've...


View more questions Search