Author Topic: A Small Question  (Read 1592 times)

Aegwyn

  • Newbie
  • *
  • Posts: 4
  • Kudos: 0
A Small Question
« on: 6 September 2002, 11:54 »
Hey, everyone.
I've been trying desperately to learn C, or at least some language. And I seem to have come up against a sort of barrier.... You'll laugh, when you see it, but I refuse go one step further before I make this darn thing work...

Code: [Select]

Obviously, that's not ACTUALLY what I'm trying to do. Really.   . It's just a small program I made to isolate and study the problem I was having, with some success.

Now, I managed to make the loop work for buying things, which was more than my original, totally overdone code did. But, for some inexplicable reason, I cannot make the darn thing go back at  "default:". It just skips straight to the end.

So, can someone point out my almost certainly ridiculously obvious dilemma? Before it drives me totally insane?  

Service With A Smile ,
Aegwyn
If you open your mind sufficently, people will throw a lot of rubbish in.

William A Thomas


Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
A Small Question
« Reply #1 on: 6 September 2002, 12:15 »
hey, i think i spotted the problem - you've got a little     in the middle of your code! take that out and it should all work fine!   ;)     :D     :D     :D

[ September 06, 2002: Message edited by: Calum ]

visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

Bazoukas

  • Member
  • **
  • Posts: 866
  • Kudos: 140
    • http://whitehouse.com
A Small Question
« Reply #2 on: 6 September 2002, 12:24 »
lolol calum


 Ill try to help you man. But i might not be able since i do C++. But i will take a look at it now.
Yeah

Bazoukas

  • Member
  • **
  • Posts: 866
  • Kudos: 140
    • http://whitehouse.com
A Small Question
« Reply #3 on: 6 September 2002, 12:36 »
i think i fixed it

 try it and tell me whats going on.

#include <stdio.h>

int continuer,smallchickenamount,mediumchickenamount,largechickenamount;
char shoppingcounter;

main()
{
int money;
money=200;
continuer=2;
largechickenamount=0;
mediumchickenamount=0;
smallchickenamount=0;
printf("Welcome to the Shopping Interface 2002.\n");


while( continuer )
{

printf("You have three choices the the Shopping interface\n");
printf("S: Buy a small chicken(50 Gold)\n");
printf("M: Buy a medium chicken(100 Gold)\n");
printf("L: Buy a large chicken(200 Gold)\n");
printf("Which do you want? S, M or L?\n");
printf("Right now you have %d S, %d M and %d L.\n",smallchickenamount,mediumchickenamount,largechickenamount);
scanf("%s",&shoppingcounter);

switch( shoppingcounter )
{
case 'S': printf("You bought a small chicken.\n");
if(money<50)

break;
else if(money>=50)
{
money=money-50;
smallchickenamount=smallchickenamount+1;
printf("Isnt that nice!\n");
continue;
}
break;
case 'M': printf("You bought a medium chicken.\n");
if(money<100)

break;
else if(money>=100)
{
money=money-100;
mediumchickenamount=mediumchickenamount+1;
printf("Isnt that nice!\n");
continue;
}
break;
case 'L': printf("You bought a large chicken.\n");
if(money<200)

break;
else if(money>=200)
{
money=money-200;
largechickenamount=largechickenamount+1;
printf("Isnt that nice!\n");
continue;

   }
break;
default:
   printf("Woops! Thats a screwup!\n");
continuer=2;
continue;

}

if(continuer==2)
{
continuer=1;
continue;
}
else if(continuer==1)
break;
}

printf("Ah well. You ran out of money. Too bad!\n");
printf("In the end, you had:\n");
printf("%d Small chickens\n",smallchickenamount);
printf("%d Medium chickens\n",mediumchickenamount);
printf("And %d Large chickens\n",largechickenamount);
}
Yeah

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
A Small Question
« Reply #4 on: 6 September 2002, 13:26 »
You were just missing a "break" at the end of your "default":

Code: [Select]

[ September 06, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...

Aegwyn

  • Newbie
  • *
  • Posts: 4
  • Kudos: 0
A Small Question
« Reply #5 on: 8 September 2002, 21:44 »
Nyahh!!!

Unfortunately, both voidmain *and* bazoukas' code still have the same darn problem... That is...
Try putting anything *BUT* S, M, or L in the input doohickey. You will very quickly find that you'll just get promptly kicked out of the loop, with no way back in.

Is there a better way to do this than my half attempt? Perhaps put the 'back into the loop' thingy afterwards? But, on second thought, that might get a little ugly...

Can anyone help me? Or is it just my wacko MPW compiler, and it works fine everywhere else?

Service With A Smile: ),
Aegwyn

[Edit: Ah! I can't even remember what I've called myself... Stupid internet. :D  ]

[ September 08, 2002: Message edited by: Aegwyn ]

If you open your mind sufficently, people will throw a lot of rubbish in.

William A Thomas


Bazoukas

  • Member
  • **
  • Posts: 866
  • Kudos: 140
    • http://whitehouse.com
A Small Question
« Reply #6 on: 8 September 2002, 21:52 »
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
y
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
5
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
,
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
1
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
!
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
k
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
l
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.
;
Woops! Thats a screwup!
You have three choices the the Shopping interface
S: Buy a small chicken(50 Gold)
M: Buy a medium chicken(100 Gold)
L: Buy a large chicken(200 Gold)
Which do you want? S, M or L?
Right now you have 0 S, 0 M and 0 L.

 I tried these characters and it didnt kick me out of the loop.
   Unless you are asking about something else and I didnt get it.
Yeah

Aegwyn

  • Newbie
  • *
  • Posts: 4
  • Kudos: 0
A Small Question
« Reply #7 on: 8 September 2002, 21:54 »
Meh...
Must be MPW. Oh well, looks like I'm going to have to tackle this problem from another completely different angle. If I can be bothered to.  ;)

Service With A Smile ,
Aegwyn
If you open your mind sufficently, people will throw a lot of rubbish in.

William A Thomas


Bazoukas

  • Member
  • **
  • Posts: 866
  • Kudos: 140
    • http://whitehouse.com
A Small Question
« Reply #8 on: 8 September 2002, 21:56 »
kinda feels good though that you are better than your compiler huh   :D
Yeah

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
A Small Question
« Reply #9 on: 8 September 2002, 17:44 »
Aegwyn, you were *definitely* missing a "break" where I said, and after I added the break it worked properly. I suspect that you were still running an old binary copy of your program. Verify the source code has the "break", compile it and then look at the times on the binary that you are going to run and compare with the source code time that you compiled from and don't forget to put the "./" in front of the binary name (./shop). The time on the binary should be newer than than the source you copied from my example.
Someone please remove this account. Thanks...