Question

Write a program that provides a customer with the price of his/her choice of a specific...

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

Homework Answers

Answer #1

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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C: character specified: R You are to write a program that will compare characters the...
In C: character specified: R You are to write a program that will compare characters the user enters to a known character Your code should first prompt for the number of values the user will enter, then loop to allow the user to enter the characters. After each character is entered your code should print out whether the character comes before, after, or is, the known character specified . Your code should also keep track of how many total characters...
Need in Java coding Write a program that will allow users to enter different types of...
Need in Java coding Write a program that will allow users to enter different types of books into the program, and at the end print out everything that the user entered. Allow the user to enter as many books as they want. Please collect the following information and break down the classes as follows using inheritance/classes. I have added the extra properties that each class should include. Book types: Paper Book (nothing extra) Comic Book (issue number) Magazine (publisher, issue...
Ice Cream Program Assignment Write a program in c# that uses a function to ask the...
Ice Cream Program Assignment Write a program in c# that uses a function to ask the user to choose an ice cream flavor from a menu (see output below.) You must validate the users input for the flavor of ice cream accounting for both upper and lower-case letters. You must give them an appropriate error message and allow them to try again.   Once you have a valid flavor, your function will return the flavor back to the main() function.   ...
Using Python: Write a program which includes functions to calculate the area, perimeter and diameter of...
Using Python: Write a program which includes functions to calculate the area, perimeter and diameter of a circle. You should have a functions compute_area(), compute_perimeter() and compute_diameter(). In addition, you should have a main() function. Your main function should ask the user for the radius of a circle, then ask the user if they would like to compute the area, the perimeter or the diameter. The user should enter "A" for area, "P" for perimeter and "D" for diameter. Your...
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's...
WRITE A JAVA PROGRAM 1. Assignment Description Write a stock transaction program that calculates a customer's profit (or loss) within a certain period of time. 1) First, the program need to get user's name, the stock's code, number of shares and the price he/she purchased the stock, it also asks the user for the price he/she sold the stock later on. The program then compute the following: The amount of money the customer paid for the stock. The amount of...
Write/test a Java program regarding the following: A parent registered his/her own child for afterschool club...
Write/test a Java program regarding the following: A parent registered his/her own child for afterschool club at the local recreation center. There is a standard fee applied to the after school program but there is a late fee added to each minute that the child is picked up late. The information below states the fee rates Weekly Fees: $90 Monday thru Friday Late Fee per minute: $10 The recreation center is open Monday through Friday: 8:00am – 10:00pm After school...
Problem a (PA5a.java) Write a program that deals with inflation, which is essentially the rising cost...
Problem a (PA5a.java) Write a program that deals with inflation, which is essentially the rising cost of general goods over time. That is, the price of goods, such as a packet of peanuts, goes up as time goes by. So, you will write a program to gauge the expected cost of an item in a specified number of years. The program asks for the cost of the item, the number of years, and the rate of inflation. The output is...
Hi, I need a program in C, where it will prompt a user for a math...
Hi, I need a program in C, where it will prompt a user for a math quiz, either easy or medium. If the user choses difficulty easy, it will prompt the user for how many questions they would like from 1-5. If the user enters medium it will prompt the user on how many questions they would like from 1-10. After those prompts are entered questions will be displayed using rand(), the questions must be multiple choice or division, aswell...
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...