// This is an example of very bad style... // Let's see if we can clean it right up. // How is everyone feeling, dizzy yet? // /* 1. What do you think this program does? // 2. Can you see any mistakes? // 3. How do we fix *this*? */ #include #define Budget 10 #define O_S 1.25 struct ice_cream { double price; int scoop; char flavour;}; enum flavours {DULCE,VANILLA,CHOC,mint, PISTACHIO}; int main() { struct ice_cream bill; int total = 0; char loop = 'y'; int scanf_return; // I am assigning to the bill structure - the price member gets the value 1.25 bill.price = O_S; while (loop == 'y') { // ?! printf("Starting .........\n"); // Printing out a statement printf("What flavour do you want and how many scoops of that flavour: "); // print out another statement scanf_return = scanf(" %c %d", &bill.flavour, &bill.scoop); if (scanf_return != 2) printf("Error, you did not put in flavour and scoops. Did you now? \n"); return 1; total = total + (bill.price * bill.scoop); if (total > Budget) printf("You do not have enough money to buy this much ice-cream.\n"); else printf("Yay! You have enough to get some ice-cream\n"); printf("Would you like to try ordering more ice-cream (y/n)? "); scanf(" %c", &loop); } return 0; }