You are running a roadside fruit stand where you sell Apples, Bananas, Oranges, and Pears.
You are to create a program that calculates the total cost of a customer’s purchase. Your program will allow the user to enter any number of the various items. Your program should prompt the user to enter a code for the product: A = apples; B = bananas, etc. and the amount they are purchasing in pounds (double precision number). You must account for both lower and upper case input characters.
Your program will continue to ask for purchase input until the user enters ‘X’ for the product code. This means that your main function will have a while loop which asks for input.
Your program must contain a function which calculates the cost of a single fruit being purchased. This function will take in a char code (A, B, O, P) indicating the type of fruit. The second parameter is the amount of fruit in pounds. The function will return the cost of the fruit. Cost is price per pound * pounds.
Apples are $1.99 / lb.
Bananas are $0.89 / lb.
Oranges are $1.19 / lb.
Pears are $1.49 / lb.
Use a switch statement to calculate the price of a fruit based on the fruit code (A,B,O,P). Return that dollar amount to main.
In main, use your while loop to take input from the user, calling the calculate function each time the user enters a fruit code and the weight. Main must keep a running total of all the purchases until the code ‘X’ is entered.
Output the total cost of the purchase. Your output should be formatted with a $ and two digits of precision.
#include <iostream>
#include <string>
using namespace std;
int main ()
{
char Apples = 1.99;
char Bananas = 0.89;
char Oranges = 1.19;
char Pears = 1.49;
char checkout;
char choice;
int total;
int a;
int b;
int c;
int d;
cout << " What would you like to Purchase " << endl;
cout << " 1. [A]pples 1.99/lb " << endl;
cout << " 2. [B]ananas 0.89/lb " << endl;
cout << " 3. [O]ranges 1.19/lb " << endl;
cout << " 4. [P]ears 1.49/lb " << endl;
cin>>choice;
if ( choice=='A')
{
cout << " How many LBS would you like to buy? " << endl;
cin >> a;
total= Apples*a;
}
else if (choice =='B')
{
cout << " How many LBS would you like to buy? " << endl;
cin>>b;
total = Bananas*b;
}
else if (choice == 'O')
{
cout << " How many LBS would you like to buy? " << endl;
cin>>c;
total = Oranges*c;
}
else if (choice=='P')
{
cout << " How many LBS would you like to buy? " << endl;
cin>>d;
total = Pears*d;
}
else if (choice=='X')
{
cout << " Would you like to check out? " << endl;
cin>>checkout;
total= A+B+O+P;
}
Can you tell me about char type, what can it hold? What would be a better type? There is a big clue in the assignment.
int total; What would be a better type for this, considering we want to have decimal places?
Your program must contain a function which calculates the cost of a single fruit being purchased. This function will take in a char code (A, B, O, P) indicating the type of fruit. The second parameter is the amount of fruit in pounds. The function will return the cost of the fruit. Cost is price per pound * pounds.