Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 My loop stopped looping O_o
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dan_




PostPosted: Wed Oct 11, 2006 3:39 pm   Post subject: My loop stopped looping O_o

Coding in C using DevC++

I'm using my own written functions and have to make a guessing game and arithmetic game. I have the arithmetic game done, but my guessing game stops looping once you get the correct answer and I can't find what is making it stop looping. I checked the braces, and they all seem to be there, and the while loop is supposed to keep looping as long as the case is true which it is.

Once you get the correct answer, the loop is just stopping for some reason, and I can't find it. The guessing game starts on line 48, and the coding for it at the bottom starts on line 139. Appreciate any help. Smile



03.c
 Description:

Download
 Filename:  03.c
 Filesize:  5.99 KB
 Downloaded:  747 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Wed Oct 11, 2006 5:21 pm   Post subject: (No subject)

The guessing game function is supposed to exit when the user guesses the correct thing... perhaps I'm missing something, or you've got yourself mighty confused.
Dan_




PostPosted: Wed Oct 11, 2006 7:07 pm   Post subject: (No subject)

It's supposed to exit the loop for telling the person they need to guess higher or lower and show them the menu again.
md




PostPosted: Wed Oct 11, 2006 7:21 pm   Post subject: (No subject)

Dan_ wrote:
It's supposed to exit the loop for telling the person they need to guess higher or lower and show them the menu again.


Wha? That's not at all how the program is designed. The code is definitely not even structured to do that. Is this even your code?
Dan_




PostPosted: Wed Oct 11, 2006 7:25 pm   Post subject: (No subject)

Yes...
You enter the loop for the menu once you selected the guessing game option. Then once you enter the number you want the guessing game to be up to it enters a loop to tell you whether you need to guess lower or higher, and once you guess right it should print that you got it right, and repeat the menu for choosing the arithmetic game, the guessing game, print your score, or close it.
md




PostPosted: Wed Oct 11, 2006 7:56 pm   Post subject: (No subject)

Ahh, your right; I was looking at code before, I didn't acutally run it. Sorry Razz

It seems though careful placement of additional prints that the error is somewhere in numDigits() it seems like it might be that the loop never ends, but I didn't put any more effort into debugging it.
Dan_




PostPosted: Wed Oct 11, 2006 8:06 pm   Post subject: (No subject)

That could very well be it. When my friend was trying to help me with it he had me change numDigits to numdigits and I still had to keep numdigits or something, he confused me. Laughing There is definitely an infinite loop going on because it's not accepting input.
Dan_




PostPosted: Wed Oct 11, 2006 8:16 pm   Post subject: (No subject)

I can't edit my post. Sad

I think it might be that number isn't equalling anything? I set it to
code:
number == max
in a previous function definition, so it's probably just picking some random number for number than because it isn't defined in this function right?
Sponsor
Sponsor
Sponsor
sponsor
Dan_




PostPosted: Wed Oct 11, 2006 9:41 pm   Post subject: (No subject)

I found the problem, it was in the numDigits part, I needed a * for multiplication because it was just resulting in an instance always repeating.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: