I'm testing this sample fast food chain program and my problem is every time I select the order the resulting price is like Php895764796364227741000000000000000.0000

Here's the code:

#include<stdio.h>

main()
{
int choice;
float TP;
clrscr();
printf("Welcome to Greenwich!\n\n");
printf("This is our menu:\n");
printf("1. Overloaded Pizzas\n");
printf("2. Extreme Cheese Overload\n");
printf("3. Classic Italian Pizza\n");
printf("4. Classic Favorites\n");
printf("5. Pastas\n");
printf("6. Chicken\n");
printf("7. Baked Rice Melt\n");
printf("8. Big Time Lucnch/ Snack Loads\n");
printf("\nPlease select a category:\n");
scanf("%d", &choice);

switch (choice)
    {
	case 1:
	clrscr();
	printf("OVERLOADED PIZZAS:\n\n");
	printf("1. Greenwich Special Overload 18' Pizza			Php%.2f\n", 749.00);
	printf("2. Meat N' Cheese Overload Pizza Square			Php%.2f\n", 501.00);
	printf("3. Greenwich Special Overload Pizza Square		Php%.2f\n", 501.00);
	printf("4. Greenwich Special Overload Family Thin		Php%.2f\n", 417.00);
	printf("5. Greenwich Special Overload Double Thin		Php%.2f\n", 248.00);
	printf("6. Greenwich Special Overload Double Thick Rolled Edge	Php%.2f\n", 292.00);
	printf("7. Meat N' Cheese Overload Family Thin			Php%.2f\n", 417.00);
	printf("8. Meat N' Cheese Overload Family Thin Rolled Edge	Php%.2f\n", 416.00);
	printf("9. Meat N' Cheese Overload Double Thin			Php%.2f\n", 248.00);
	printf("10. Meat N' Cheese Overload Double Thick Rolled Edge	Php%.2f\n", 292.00);
	printf("11. Fantastic G4					Php%.2f\n", 749.00);
	printf("12. Sqauare Half and Half				Php%.2f\n", 501.00 );
	printf("13. 7-Cheese Overload					Php%.2f\n",229.00);
	printf("14. Hawaiin Overload					Php%.2f\n", 199.00);
	printf("15. Meat N' Cheese Overload				Php%.2f\n", 349.00);
	printf("\nMay I take your order?\n");
	scanf("%d", &choice);
	printf("\nYour bill is Php%f", TP);


	getch();

	break;

	case 2:
	break;
	}
getch();
}

hope someone could help me

Recommended Answers

All 6 Replies

Try initializing TP to 0.0.

Didn't work sir. The output would be "Your bill is Php0.0".

Didn't work sir. The output would be "Your bill is Php0.0".

Try assigning something to TP.

Sorry but what do you mean by assigning somthing to TP? Sorry I'm a beginner.

I'm testing this sample fast food chain program and my problem is every time I select the order the resulting price is like Php895764796364227741000000000000000.0000

Your code is incomplete. You're trying to print the resulting price 'TP' without assigning any value to it.

printf("\nMay I take your order?\n");
scanf("%d", &choice);
/* switch statement is missing*/
/*like this */
/*case '1':
     TP=749.00;/* This is called "assigning a value"
     break;
     
  case '2':
     Tp=501.00;
     break;
  ...          */
printf("\nYour bill is Php%f", TP);/*and then print the value*/

Here's the code:

#include<stdio.h>

main()
{
int choice;
float TP=0.00;
clrscr();
printf("Welcome to Greenwich!\n\n");
printf("This is our menu:\n");
printf("1. Overloaded Pizzas\n");
printf("2. Extreme Cheese Overload\n");
printf("3. Classic Italian Pizza\n");
printf("4. Classic Favorites\n");
printf("5. Pastas\n");
printf("6. Chicken\n");
printf("7. Baked Rice Melt\n");
printf("8. Big Time Lucnch/ Snack Loads\n");
printf("\nPlease select a category:\n");
char ch;
float pizza_price[15]={749.00,501.00,501.00,417.00,248.00,292.00,417.00,416.00,248.00,292.00,749.00,501.00,229.00,199.00,349.00};
while(ch==y||ch==Y)
{
scanf("%d", &choice);

switch (choice)
    {
	case 1:
	clrscr();
	printf("OVERLOADED PIZZAS:\n\n");
	printf("1. Greenwich Special Overload 18' Pizza			Php%.2f\n", 749.00);
	printf("2. Meat N' Cheese Overload Pizza Square			Php%.2f\n", 501.00);
	printf("3. Greenwich Special Overload Pizza Square		Php%.2f\n", 501.00);
	printf("4. Greenwich Special Overload Family Thin		Php%.2f\n", 417.00);
	printf("5. Greenwich Special Overload Double Thin		Php%.2f\n", 248.00);
	printf("6. Greenwich Special Overload Double Thick Rolled Edge	Php%.2f\n", 292.00);
	printf("7. Meat N' Cheese Overload Family Thin			Php%.2f\n", 417.00);
	printf("8. Meat N' Cheese Overload Family Thin Rolled Edge	Php%.2f\n", 416.00);
	printf("9. Meat N' Cheese Overload Double Thin			Php%.2f\n", 248.00);
	printf("10. Meat N' Cheese Overload Double Thick Rolled Edge	Php%.2f\n", 292.00);
	printf("11. Fantastic G4					Php%.2f\n", 749.00);
	printf("12. Sqauare Half and Half				Php%.2f\n", 501.00 );
	printf("13. 7-Cheese Overload					Php%.2f\n",229.00);
	printf("14. Hawaiin Overload					Php%.2f\n", 199.00);
	printf("15. Meat N' Cheese Overload				Php%.2f\n", 349.00);
	printf("\nMay I take your order?\n");
	scanf("%d", &choice);
        TP=TP+pizza_price[choice];
        printf("any thing else")
        scanf("%c",&ch);
        
}
	printf("\nYour bill is Php%f", TP);


	getch();

	break;

	case 2:
	break;
	}
getch();
}

try this one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.