`#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i, order, o;
double total;
char split;
i=1;
total=0.0;
printf("Welcome! How many drinks will be ordered?\n");
scanf("%d",&order);
while(i<=order)
{
printf("\nMENU: \n1. Espresso \n2. Latte \n3. Cappuccino \n4. Tea\n");
scanf("%d",&o);
switch(o)
{
case 1:
printf("You have ordered one Espresso, which costs 4.5$");
total=total+4.5;
break;
case 2:
printf("You have ordered one Latte, which costs 5.5$");
total=total+5.5;
break;
case 3:
printf("You have ordered one Cappuccino, which costs 6.5$");
total=total+6.5;
break;
case 4:
printf("You have ordered one Tea, which costs 3.5$");
total=total+3.5;
break;
}
i=i+1;
}
printf("Would you like to split the bill between 3 guests?\n");
scanf("%c",&split);
switch(split)
{
case 'y':
case 'Y':
total=total/order;
printf("The amount that each guest needs to pay is %2.1f$",total);
break;
case 'n':
case 'N':
printf("The total amount that you need to pay is: %2.1f$\n",total);
break;
}
return(0);
}
`
Kod bu while bittikten sonra printf ile Would you like to split the bill between 3 guests? sorusu gelip cevap alınması gerekiyor fakat while bittikten sonra printleyip input girmeme izin vermeden direk bitiyor.
Benim run
"
Welcome! How many drinks will be ordered?
3
MENU:
- Espresso
- Latte
- Cappuccino
- Tea
1
You have ordered one Espresso, which costs 4.5$
2
You have ordered one Latte, which costs 5.5$
4
You have ordered one Tea, which costs 3.5$
Would you like to split the bill between 3 guests?
Process exited after 5.111 seconds with return value 0
Press any key to continue . . .
"
Olması gereken ise bu
"Welcome! How many drinks will be ordered? 3
MENU: 1. Espresso 2. Latte 3. Cappuccino 4. Tea
1
You have ordered one Espresso, which costs 4.5$
2
You have ordered one Latte, which costs 5.5$
4
You have ordered one Tea, which costs 3.5$
Would you like to split the bill between 3 guests?
Y
The amount that each guest needs to pay is 4.50$"
Neyi yanlış yaptım acaba?