I'm going through the C Programming Absolute Beginners Guide 3rd edition to learn programming and I'm having issues at Chapter8ex2.c where my program gets the cost and then is supposed to get the topping. It instead passes by that and reuses the first variable instead of using the correct second one.
here is my code
// This is a sample program that asks users for some basic data and prints it on
// the screen in order to show what was entered
#include <stdio.h>
int main()
{
char topping[24];
int slices;
int month, day, year;
float cost;
// The first scanf will look for a floating-point variable, the cost of the pizza
// If the user doesn't enter a $ before the cost, it could cause problems
printf("How much does a pizza cost in your area?");
printf("enter as $XX.XX)\n");
scanf(" $%f", &cost);
// The pizza topping is a string, so your scanf doesn't need an &
printf("What is your favorite one-word pizza topping?\n");
scanf(" %s", topping);
printf("How many slices of %s pizza", topping);
printf("can you eat in one sitting?\n");
scanf("%i", &slices);
printf("What is today's date (enter it in XX/XX/XX format).\n");
scanf(" %i/%i/%i", &month, &day, &year);
printf("\n\nWhy not treat yourself to dinner on %i/%i/%i", month, day, year);
printf("\nand have %i slices of %s pizza!\n", slices, topping);
printf("It will only cost you $%.2f!\n\n\n", cost);
return(0);
}
here is the code being run
How much does a pizza cost in your area?enter as $XX.XX)
15.00
What is your favorite one-word pizza topping?
How many slices of 15.00 pizzacan you eat in one sitting?