Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C (https://www.askmehelpdesk.com/forumdisplay.php?f=438)
-   -   Why does my C program keep looping? (https://www.askmehelpdesk.com/showthread.php?t=743626)

  • Apr 10, 2013, 01:44 PM
    InfoJunkie4Life
    1 Attachment(s)
    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.
  • Apr 13, 2013, 06:00 PM
    InfoJunkie4Life
    No C programmers on this forum anymore?

    I love it anyway... lol
  • Apr 22, 2013, 08:15 PM
    InfoJunkie4Life
    1 Attachment(s)
    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.
  • Apr 23, 2013, 09:09 AM
    cdad
    I have to ask. Does the program your using have a debugger built in that you can see line by line what is happening?
  • Apr 23, 2013, 03:24 PM
    InfoJunkie4Life
    Yes it does, however I did not think to use it. I will try it tonight with both sources, then I'll post back.

  • All times are GMT -7. The time now is 09:48 AM.