First stage of solution :)
Code:
#include <iostream>
const double MILKPRICE = 1.37,EGGPRICE = 1.29,BREADPRICE = 0.88;
class menu
{
int egg, milk, bread;
double total;
public:
menu();
void get_list();
double total_cost();
void debit_bill();
};
menu::menu()
{
egg = milk = bread = 0;
total = 0.0;
}
void menu::get_list()
{
std::cout << "Enter the no: of eggs (0 if not needed)";
std::cin >> egg;
std::cout << "Enter the no: of liters of milk (0 if not needed)";
std::cin >> milk;
std::cout << "Enter the loaves of bread (0 if not needed)";
std::cin >> bread;
}
double menu::total_cost()
{
total = MILKPRICE * milk + EGGPRICE * egg + BREADPRICE * bread;
return total;
}
void menu::debit_bill()
{
std::cout << "Item\t\tQuantity\t\tPrice" << std::endl;
std::cout << "Egg \t\t" << egg << "\t\t\t" << EGGPRICE * egg << std::endl;
std::cout << "Milk\t\t" << milk << "\t\t\t" << MILKPRICE * milk << std::endl;
std::cout << "Bread\t\t" << milk << "\t\t\t" << BREADPRICE * bread << std::endl;
std::cout << "Total\t\t\t\t\t" << total <<std::endl;
double cash_accept;
std::cout << "Enter the amount given by the customer" << std::endl;
std::cin >> cash_accept;
if(cash_accept < total)
{
std::cout << "Pay up buddy.. no credit accepted" << std::endl;
}
else
{
std::cout << "You have been kind... i will keep the change" << std::endl;
}
}
int main()
{
menu m1;
m1.get_list();
m1.total_cost();
m1.debit_bill();
return 0;
}
PS: Its preferable, not to post assignment type questions on this board.