Reputation: 141
The problem is that I don't know how to exit from my loop.
printf ("Do you order fish? (Y/N): ");
scanf ("%c", &f);
while((f == 'y')||(f == 'Y'))
{
do {
fish = getfish_choice();
printf ("Total of you fish is %.2lf\n", sum);
printf ("Do you want to order more fish?(Y/N)");
scanf (" %c", &morefish);
}
while ((morefish=='Y')||(morefish=='y'));
}
Printf ("Hello");
How could I exit this loop so the output of my code will read Hello?
Upvotes: 0
Views: 229
Reputation: 471209
What's happenning is that when Y
or y
is entered, you manage to break out of the inner loop, but you're still stuck in the outer loop. (f
is never modified)
You don't even need two loops:
printf ("Do you order fish? (Y/N): ");
scanf ("%c", &morefish);
while ((morefish=='Y')||(morefish=='y')){
fish = getfish_choice();
printf ("Total of you fish is %.2lf\n", sum);
printf ("Do you want to order more fish?(Y/N)");
scanf (" %c", &morefish);
}
printf ("Hello");
Upvotes: 1
Reputation: 272467
You have a while
loop whose condition involves checking f
. But you never modify f
.
So perhaps that first while
should actually be an if
.
Upvotes: 2