Idea behind the Program and at the end is what I worte what am I doing wrong???

Can someone write this program!! Thanks I can not figure it out

Write the C++ code that will contain 4 functions:

1. A void function named bestbuy that accepts three prices as float values and returns the smallest price and the number of the price as parameters. Return a 1 for the number if the first price is the lowest, a 2 if the second price is the lowest, and a 3 if the third price is the lowest.

2. A void function named discountresults that accepts a price and a discount percent as float values and returns the discount amount and discounted price as parameters. Return these values as float values.

3. A void function named howmany that accepts the amount of money available and the cost of an item as float values and returns the number of items that can be purchased as an integer parameter and the amount of money left over from the purchase as parameters.

4. A function named menu that returns a character and does not accept any parameters. This function will display:

(B)est Buy Calculation
(D)iscount Calculation
(H)ow Many Calculation
(Q)uit

Please enter the option (B,D,H, or Q)

The main function will continue looping until Q is entered. Depending on which character is entered, the program will request the information for the function, pass the parameters into the function, and display to the monitor the returned values from the function.

Example:

(B)est Buy Calculation
(D)iscount Calculation
(H)ow Many Calculation
(Q)uit

Please enter the option (B,D,H, or Q) B


Please enter 3 prices 12.13 15.14 8.95
The smallest price is 8.95 and is price number 3


(B)est Buy Calculation
(D)iscount Calculation
(H)ow Many Calculation
(Q)uit

Please enter the option (B,D,H, or Q) D


Please enter a price and a discount amount 11.00 .10
The discount amount is 1.10 and the discounted price is 9.90

(B)est Buy Calculation
(D)iscount Calculation
(H)ow Many Calculation
(Q)uit

Please enter the option (B,D,H, or Q) H


Please enter amount available and cost of each 10.00 2.15
You can buy 4 and have 1.40 left over.

(B)est Buy Calculation
(D)iscount Calculation
(H)ow Many Calculation
(Q)uit

Please enter the option (B,D,H, or Q) Q


This is what I wrote

#include<iostream>
#include<iomanip>
using namespace std;

void discountresults (float price,float percent,float damount,float dprice);
void howmany (float money,float cost,float amt,float cashleft);
char menu();

int main ()
{
float price,percent,damount,dprice,money,cost,cashleft, amt;
char selection;
while(selection!='Q')
{
selection=menu();
cin>>selection;
switch(selection)
{case 'D':discountresults(price,percent,damount,dprice);
break;
case 'H':howmany(money,cost,amt,cashleft);
break;
case 'Q':break;
}
}
return 0;
}
char menu()
{
cout<<"(B)est Buy Calculation"<<endl;
cout<<"(D)iscount Calculation"<<endl;
cout<<"(H)ow Many Calculation"<<endl;
cout<<"(Q)uit"<<endl;
cout<<endl;
cout<<"Please enter the option (B,D,H,or Q) "<<endl;
}
void discountresults (float price, float percent, float damount, float dprice)
{
cout<<"Please enter a price and a discount amount "<<endl;
cin>>price;
cin>>percent;
damount=price*percent;
dprice=price-damount;
cout<<"The discount amount is "<<damount;
cout<<" and the discounted price is "<<dprice<<endl;

}
void howmany (float money,float cost,float amt, float cashleft)
{
cout<<"Please enter amount available and cost of each"<<endl;
cin>>money;
cin>>cost;
amt=money/cost;
amt=(int)amt;
cashleft=money-amt*cost;
cout<<"You can buy "<<amt;
cout<<" and have "<<cashleft;
cout<<" left over."<<endl;
cashleft=money-amt*cost;

}

Last edited on
Never ask for a program, try doing something and ask if you get problems http://www.cplusplus.com/forum/articles/1295/

This assignment is really easy as you just need to translate instruction given into C++
Topic archived. No new replies allowed.