Thread: help, please....

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    1

    **edit**code check

    I'm supposed to write a program with the following information, but I'm not exactully sure how because of poor examples from my source books. im supposed to use loops



    You will have 3 functions in addition to the main function
    Get_list will print the list for the user and get the input from the user
    Total_cost will calculate the total cost of the items
    Take_money will print the bill, get the debit input from the user and print the change. Use an error trap so that a debit of more than $20.00 over the bill or a debit less than the bill will not be accepted.

    You will need to use the following constants
    MILKPRICE = 1.37
    EGGPRICE = 1.29
    BREADPRICE = .88


    Code:
    Here is your main function. You must use this in your program - do not change it.
    
    //=============================main=============
    int main()
    { int eggs, milk, bread;// entered by user
    float bill;// calculated
    
    Get_list(eggs, milk, bread);
    bill = Total_cost(eggs,milk,bread);
    Take_money(bill);
    
    return 0;
    }// end main

    ****edit***opps, sorry...i forgot to add what i had come up with so far. i'm sorry, i wouldn't want to do someone one elses homework either**

    Code:
    #include <iostream.h>
    
       
    
    
    //=============================main========================
    int main()  
    
    { int eggs, milk, bread;// entered by user
    float bill;// calculated 
    
    egg=milk=bread=0;
    bill= 0.0;                 
    
    
    
    Get_list(eggs, milk, bread);
    bill = Total_cost(eggs,milk,bread);
    Take_money(bill);
    
    return 0;
    }// end main   
    
    const double MILKPRICE = 1.37, EGGPRICE = 1.29, BREADPRICE = 0.88
    
    
    ///==================Get_list=========  
    void Get_list()
    {
      cout<< " Please enter the number or items you would like"<<endl;   
      
      cout<< " How many quarts of milk @ $1.37 :  "<<endl;
      cin>> milk; 
      
      cout<< " How many dozens of eggs @ $1.29 : "<<endl;
      cin >> eggs;    
      
      cout<< " How many loaves of bread @ $0.88 : " << endl;
      cin >> bread;
    
    } //end get_list
    
    
    //==========Total_cost==========
     {
    Total_cost= MILKPRICE * milk + EGGPRICE * eggs + BREADPRICE * bread 
     } // end Total_cost
     
     
     //==========Take_money=====
     {
       cout<<"Your total bill is: "<<bill<<endl;  
       
       cout<<"Please enter the amount you want debited:"<<endl;
       cin>>Take_money;
       
       if(Take_money >50)
       	{
       		cout<<"Sorry, you have a limit of $20.00 over your bill." << endl;
       		cout<< Your maimum debit can be" << bill + 20<< endl;
       		cout<< "Please reenter your debit amount:<<endl;
       	}  
       	
       	
      }//end Take_money
    Last edited by my stereos a li; 01-20-2003 at 06:07 AM.

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    We're not going to do your homework for you. At least start it and post what you get. We'll help you fix it up if it's still not working.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    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.
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Titles like "HELP ME PLEASE" and "IM GOING TO KILL MYSELF
    IF YOU DONT HELP ME!" are im affraid not allowed

Popular pages Recent additions subscribe to a feed