Hit a brick wall

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Hit a brick wall

Post by ayu »

Ok guys, I've been staring on this code for hours now, and I just can't figure it out. The code isn't finished yet, but I don't want to continue with it until I solved this problem.

Code: Select all

http://code.suck-oold.com/79
The problem is this part

Code: Select all

while(1)
	{
		cout << "Which cookie do you want to eat? ";
		cin >> choice;

		if(CookieEaten[choice-1] == true)
		{
			CookiesEatCount[choice-1]++;

			if(CookiesEatCount[choice-1] > 1)
				cout << "You can't eat a cookie " << CookiesEatCount[choice-1] << "times\n";
			else
				cout << "You have already eaten this cookie once\n";
		}
		else if(CookieEaten[choice-1] == false)
		{
			CookiesEatCount[choice-1]++;
			CookieEaten[choice-1] = true;
			cout << "\"" << Cookie[choice-1] << "\"\n";
		}
		
	}
It's a "game" where you choose a cookie and it gives you a fortune, and the issue is that when you try to choose a cookie that you already eaten, it gives you "You have already eaten this cookie once", and then if you try again it should give you "You can't eat a cookie X times", but the thing is that for some reason CookiesEatCount[choice-1]++;, only works once, then it stops adding =/ so CookiesEatCount never goes over 1 for some reason..and I can't see the problem with it >_<

I need 2-4 more eyes! xD
"The best place to hide a tree, is in a forest"

G-Brain
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 467
Joined: 08 Nov 2007, 17:00
16
Location: NL

Post by G-Brain »

I doubt it would do anything, but you should initialize CookiesEatCount to all 0's too.
I <3 MariaLara more than all of you

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

G-Brain wrote:I doubt it would do anything, but you should initialize CookiesEatCount to all 0's too.
it's worth a try I guess xF

I'll report back in a min ^^
"The best place to hide a tree, is in a forest"

G-Brain
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 467
Joined: 08 Nov 2007, 17:00
16
Location: NL

Post by G-Brain »

It works. I'm a genius.
Last edited by G-Brain on 23 Sep 2008, 11:39, edited 1 time in total.
I <3 MariaLara more than all of you

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

G-Brain wrote:It works. I'm a genius.
Dunno if I should be pissed or if I should give you a hug.... hen it worked -.- been trying to figure that out for hours now... >.<

It's odd though, since it went to 1, then stopped there : /

anyway....thanks ^^
"The best place to hide a tree, is in a forest"

Post Reply