Question: Make this program into a function #include #include int menu(); int main() { int option = 0; int number = 0; int amount = 0;

Make this program into a function

#include #include

int menu();

int main() { int option = 0; int number = 0; int amount = 0; float max = 0; float total = 0; float total_and_discount = 0; float discount = 0; float total_plus_tax = 0; float grand_total = 0; float available = 0;

std:: cout << "How much money is on your card?" << std:: endl; std:: cin >> max; available = max; while(grand_total < max) { std:: cout << "There is $" << available << " on your card to spend." << std::endl; option = menu(); if (option == 0) { grand_total= max + 1; } else { if (option == 1) { std:: cout << "How many half dozen or full dozen donuts would you like?" << std::endl; std:: cin >> amount; total = amount * 75; } if(option == 2) { std:: cout << " How many pairs of tie would you like?" << std:: endl; std:: cin >> amount; total = amount * 100; } if(option == 3) { std:: cout << "How many shirts would you like?" << std:: endl; std:: cin >> amount; total = amount * 150; } if(option == 4) { std:: cout << "How many jeans would you like?"; std:: cin >> amount; total = amount * 175; } if(option == 5) { std::cout << "Would you like an printer?"; std::cin >> amount; total = amount * 200; } std:: cout << std:: endl << std:: endl << "Type 1 if your item has a discount but Type 2 if your item does not" << std::endl; std:: cin >> discount; if(discount == 1) { float discountf(float total); total_and_discount = discountf(total); total_plus_tax = total_and_discount + (total_and_discount * .07); } else { total_plus_tax = total + (total * .07); } number = number + amount; if(total_plus_tax > available) { std:: cout << "You currrently only have $" << available << "so you can not make this purchase" << std:: endl << std:: endl; total_plus_tax = 0; number = number - amount; } grand_total = grand_total + total_plus_tax; std::cout << std::endl << std::endl << "you have" << number << " items in your shooping chart" << "The total cost is" << grand_total ; available = max - grand_total; } } std::cout << "You have successfuly checked out with" << number << std::endl << std::endl; std::cout << "You have $ " << available << "left on your card" << std::endl << std::endl; return 0; }

int menu() { int choice; std::cout << "Choose what item that you want that you want to buy." << std::endl; std::cout << " 1) Donuts = 75 dollars per 1/2 dozen (25% off) " << std::endl; std::cout <<" 2) Pair of ties for 100 dollars (10% off) " << std::endl; std:: cout << "3) Shirts for 150 dollars " << std::endl; std::cout << "4) Jeans for 175 dollars (5% off) " << std::endl; std:: cout << "5) Printer = $200 dollars" << std::endl; std:: cout << "0) proceed to check out" << std::endl; std:: cin >> choice; return choice; } float discountf(float total) {

float percent; float total_discount;

std::cout << " What is the discount? " << std::endl; std::cin >> percent; total_discount = total - (total * percent/100); return total_discount; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!