#include #include using namespace std; int main () { ///////////////////////// // Constant declarations // Chow amounts const int five_can_oz = 2; const int five_dry_oz = 1; const int six_can_oz = 2; const int six_dry_oz = 2; const int seven_can_oz = 3; const int seven_dry_oz = 3; const int eight_can_oz = 3; const int eight_dry_oz = 5; // Number of feeding related const int days_in_week = 7; const int meals_per_day = 3; // Food related items const int ounces_per_can = 12; const int pounds_per_bag = 10; const int ounces_per_pound = 16; const float cost_per_can = 1.25; const float cost_per_bag = 5.4; // Tax rate const float tax_rate = .04; /////////////////////////// // Variable declarations int five_week_olds = 0; int six_week_olds = 0; int seven_week_olds = 0; int eight_week_olds = 0; int ounces_dry_food = 0; int ounces_canned_food = 0; int cans_needed = 0; int bags_needed = 0; bool get_discount = false; float discount_rate = 0.0; float food_cost = 0; float food_cost_discounted = 0; float tax_cost = 0; float total_cost = 0; ////////////////////////// // Explain the program cout << "Welcome to the puppy food purchasing program" << endl << endl; cout << "Please enter the following information:" << endl; // Input the number of puppies cout << "Number of five week old puppies: "; cin >> five_week_olds; cout << "Number of six week old puppies: "; cin >> six_week_olds; cout << "Number of seven week old puppies: "; cin >> seven_week_olds; cout << "Number of eight week old puppies: "; cin >> eight_week_olds; ////////////////////////// // Calculate the number of ounces of food per meal ounces_canned_food = (five_week_olds * five_can_oz) + (six_week_olds * six_can_oz) + (seven_week_olds * seven_can_oz) + (eight_week_olds * eight_can_oz); ounces_dry_food = (five_week_olds * five_dry_oz) + (six_week_olds * six_dry_oz) + (seven_week_olds * seven_dry_oz) + (eight_week_olds * eight_dry_oz); // Since everything above is for one meal, work out what is needed // for the whole week ounces_canned_food = ounces_canned_food * meals_per_day * days_in_week; ounces_dry_food = ounces_dry_food * meals_per_day * days_in_week; ////////////////////////// // Calculate the number of cans and bags of food needed cans_needed = ounces_canned_food / ounces_per_can; // Make sure we buy an extra can if it doesn't work out exactly if ((ounces_canned_food % ounces_per_can) != 0) cans_needed = cans_needed + 1; bags_needed = (ounces_dry_food/(ounces_per_pound * pounds_per_bag)); // Make sure we buy an extra bag if it doesn't work out exactly if ((ounces_dry_food % (ounces_per_pound * pounds_per_bag)) != 0) bags_needed = bags_needed + 1; ////////////////////////// // Accounting // Find out if we have a discount char input; cout << "Did you get a discount? (y/n): "; cin >> input; if ('y'== input||'Y'==input) { get_discount = true; cout << "Enter percent of discount (example: .1 = 10%): "; cin >> discount_rate; } // calclulate the totals food_cost = (cans_needed * cost_per_can) + (bags_needed * cost_per_bag); if (get_discount){ food_cost_discounted = food_cost * (1 - discount_rate); tax_cost = food_cost_discounted * tax_rate; total_cost = food_cost_discounted + tax_cost; } else { tax_cost = food_cost * tax_rate; total_cost = food_cost + tax_cost; } ////////////////////////// // Output things neatly cout << endl << "This week we need:" << endl; cout << "Cans of food: " << cans_needed << endl; cout << "Bags of food: " << bags_needed << endl; cout << endl; //cout.setf(ios::fixed, ios::floatfield); cout << fixed; cout << setprecision(2) << "Cost of food: " << food_cost << endl; if (get_discount) cout << "Discounted cost of food: " << food_cost_discounted << endl; cout << "Tax amount: " << tax_cost << endl; cout << "Total cost: " << total_cost << endl; return 0; }