Write a program that provides a customer with the price of his/her choice of a specific fruit. If the customer selects (1), then the program should print "you select banana and the price is $1.00/lb". If he selects (2) then the program should print "you select orange and the price is $1.50/lb". If he selects (3) then the program should print "you select apple and the price is $1.90/lb". Allow the customer to make a selection, then asking "how many pounds of (apples/oranges/ bananas) would you like? Then ask if they would like to select another fruit (Yes or No) If so, allow them to select another fruit, then how many pounds they would like of the specific fruit. If the user selects (No) when asked if they'd like to select any more fruit, print how many pounds the total of each fruit they selected and their individual totals (example: You've selected 3 pounds of bananas for $3.00) Then the total sum of all of the fruit they've purchased. Example: (Your grand total is: $12.00) Then end with the printed message: "Thank you for selecting the fruits of your choice." PLEASE USE C++ using #include using namespace std
For this program we need variables for the following
1. option- to choose either 1 or 2 or 3
2. character input for yes or no, char ch
3. pounds , to ask user for required weight of fruit
to keep track of weights of each fruit we need pound1 for bananas
pounds2 for oranges
pounds3 for apples
4. price , to compute the price of fruit
to keep track of individual price totals , we need total1, total2,total3.
5. total, to store the grand total, initialized to zero
Required construct
we need switch case statement to allow choosing among 3 cases, and loop to repeat until we choose no 'n'.
-------------------------
#include <iostream>
using namespace std;
int main()
{
int option,pounds,pounds1=0,pounds2=0,pounds3=0;
float price,total1=0.0,total2=0.0,total3=0.0;
char ch;
while(1)//true loop until we press'n'
{
cout<<"choose 1 or 2 or 3 : ";
cin>>option;
switch(option)
{
case 1:cout<< "you select banana and the price is
$1.00/lb"<<endl;
cout<<"Enter pounds : ";
cin>>pounds;
price=pounds*1.00;
pounds1=pounds1+pounds; // to keep track of weight of bananas
total1=total1+price;
break;
case 2:cout<< "you select orange and the price is
$1.50/lb"<<endl;
cout<<"Enter pounds : ";
cin>>pounds;
price=pounds*1.00;
pounds2=pounds2+pounds; // to keep track of oranges
total2=total2+price;
break;
case 3:cout<< "you select apple and the price is
$1.90/lb"<<endl;
cout<<"Enter pounds : ";
cin>>pounds;
price=pounds*1.00;
pounds3=pounds3+pounds; //to track weight of apples
total3=total3+price;
break;
default:cout<<"Invalid choice"<<endl;
}//close switch-case
cout<<"Do you like to select another fruit (Yes or No) n to
stop"<<endl;
cin>>ch;
if(ch=='n'||ch=='N')
break;
}//clsoe while loop
//print individual weights of each fruit and grand total
cout<<" you have selected " <<pounds1<<" pounds
of bananas"<<endl;
cout<<" you have selected " <<pounds2<<" pounds
of oranges"<<endl;
cout<<" you have selected " <<pounds3<<" pounds
of apples"<<endl;
cout<<"Grand total =
"<<total1+total2+total3<<endl;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.