// This program keeps inventory of eggs in your refridgerator. // The user starts with a certain number of eggs in their // refridgerator. The user is asked how many cartons of // eggs they have used, and how many individual eggs in addition // to the carton, and computes the number of eggs remaining in // the refridgerator. // // For example, when you run the program you should see this: // // HOW MANY EGGS ARE IN YOUR FRIDGE? 47 // HOW MANY EGG CARTONS HAVE YOU USED? 2 // YOU HAVE 23 EGGS LEFT // [23 = 47 - 2*12] // HOW MANY INDIVIDUAL EGGS HAVE YOU EATEN? 7 // YOU HAVE 16 EGGS LEFT #include int main() { int used_egg_cartons; int current_eggs_in_fridge; int eaten_eggs; const int EGGS_IN_CARTON = 12; cout << "How many eggs are in your fridge? "; cin >> current_eggs_in_fridge; cout << "How many egg cartons have you used? "; cin >> used_egg_cartons; current_eggs_in_fridge = current_eggs_in_fridge - (used_egg_cartons * EGGS_IN_CARTON); // note: parentheses above were not necessary but were included // to be clear on the order of evaluation if (current_eggs_in_fridge < 0) { cout << "You've used more eggs than you have" << endl; current_eggs_in_fridge = 0; } else { cout << "You have " << current_eggs_in_fridge << " eggs left" << endl; cout << "How many individual eggs have you eaten? "; cin >> eaten_eggs; current_eggs_in_fridge = (current_eggs_in_fridge - eaten_eggs); // Those parentheses weren't needed either if (current_eggs_in_fridge < 0) { cout << "You've used more eggs than you have" << endl; current_eggs_in_fridge = 0; } else { cout << "You have " << current_eggs_in_fridge << " eggs left\n"; } } }