In: Computer Science
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
The program should run as followed:
Please select (1) for Bananas which are 1.00/lb
Please select (2) for Oranges which are 1.50/lb
Please select (3) for Apples which are 1.90/lb
(users selects 2)
How many pounds would you like?
(user selected 4)
Would you like to get another fruit? Yes or No
(user selected yes)
Please select (1) for Bananas which are 1.00/lb
Please select (2) for Oranges which are 1.50/lb
Please select (3) for Apples which are 1.90/lb
(users selects 1)
How many pounds would you like?
(user selects 1)
Would you like to get another fruit? Yes or No
(user selected no)
You've purchased:
4 pounds of oranges for $6
1 A pound of Bananas for $1
Your grand total is: $7
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int choice;//declaring necessary variables
float apples=0,bananas=0,oranges=0,weight;
char exit[3];
int total_price;
while(1)
{
cout << "Please select (1) for Bananas which are
1.00/lb \nPlease select (2) for Oranges which are 1.50/lb \nPlease
select (3) for Apples which are 1.90/lb\n";
cin >> choice;//reading choice
cout << "How many pounds would you
like?\n";
cin >>weight;//reading the weight
if(choice==1)
bananas+=weight;
else if(choice==2)
oranges+=weight;
else
apples+=weight;
cout << "Would you like to get another fruit?
Yes or No\n";
cin >> exit;
if (exit[0]=='N' && exit[1]=='o')
break;//if we enter No
}
if(bananas>0)
cout << bananas <<
"pounds of bananas for " << bananas <<"$\n";//printing
the final bananas cost
if(oranges>0)
cout << oranges <<
"pounds of oranges for " <<oranges*1.5
<<"$\n";//printing the final oranges cost
if(apples>0)
cout << apples <<
"pounds of apples for " << apples*1.90
<<"$\n";//printing the final apples cost
cout << "Your grand total is: $"
<<bananas+(oranges*1.5)+(apples*1.90);//total cost
return 0;
}
output: