Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programing Joey is on a budget, and has been bringing peanut butter and jell

ID: 3902151 • Letter: C

Question

C++ Programing

Joey is on a budget, and has been bringing peanut butter and jelly sandwiches to work. He would like a program which can calculate the exact cost of one peanut butter sandwich, and allow him to determine which brands of ingredients he should buy to best fit his budget. For one sandwich Joey uses 2 slices of bread, 1/20 of a jar of peanut butter and .10 (one tenth) of a jar of jelly.

Your program is to accept as input:

         * the price of a jar of peanut butter   (a double value)

         * the brand of the peanut butter   (a string value)

         * the price of a jar of jelly

         * the brand of the jelly

         * the price of a loaf of bread   (a double value)

         * the number of slices of bread   (an int value)

         * the type of the bread

Once your program has read in and stored all of the input, you are to calculate and print:

          *the cost of the peanut butter being used

          * the cost of the jelly being used

          * the cost of the bread being used (don’t forget to use 2 slices)

          * the cost of the sandwich

* Use the name of the product in the above output

For example, your program output might look like:

Please enter the price of a jar of peanut butter

3.50

Please enter the type of peanut butter

JIF

Please enter the price of a jar of jelly

4.00

Please enter the type of jelly

Welch's

Please enter the price of a loaf of break

3.00

How many slices of bread are there in a loaf

30

Please enter the type of bread

WonderBread

The cost of JIF used is $0.17

The cost of Welch's used is $0.40

The cost of the WonderBread is $0.20

The cost of the sandwich is $0.77

Press any key to continue . . .

Be sure that your program contains a comment with your name, plus short comments which indicate what is going on in the program. Also, variable names should be descriptive, and provide an idea of the howvariable is to be used.

Explanation / Answer

Code :

#include<iostream>

#include<string>

using namespace std;

int main(){

double pricePeanutButter; //initializing variables

string peanutButterType;

double jellyJarPrice;

string jellyType;

double breadPrice;

int numberOfBreadSlices;

string breadType;

//taking input

cout<<"Please enter the price of a jar of peanut butter: ";

cin>>pricePeanutButter;

cout<<"Please enter type of peanut butter: ";

cin>>peanutButterType;

cout<<"Please enter price of a jar of jelly: ";

cin>>jellyJarPrice;

cout<<"Please enter the type of jelly: ";

cin>>jellyType;

cout<<"Please enter the price of a loaf of bread: ";

cin>>breadPrice;

cout<<"How many slices of bread are there in a loaf: ";

cin>>numberOfBreadSlices;

cout<<"Please enter the type of bread: ";

cin>>breadType;

double pButterPrice = pricePeanutButter/20; //1/20 of peanut butter is used

cout<<"The cost of "<<peanutButterType<<" used is $"<<pButterPrice<<endl;

double jellyPrice = jellyJarPrice*0.10; //0.10 of jelly is used

cout<<"The cost of "<<jellyType<<" is $"<<jellyPrice<<endl;

double breadPr = breadPrice*2/numberOfBreadSlices; //2 slices of bread used

cout<<"The cost of "<<breadType<<" is $"<<breadPr<<endl;

cout<<"The cost of the sandwich is $"<<pButterPrice+jellyPrice+breadPr<<endl;

cout<<"Press any key to continue..."<<endl;

cin.get();

}

Sample Output:

radas-macOS:Desktop radas$ g++ a.cpp
radas-macOS:Desktop radas$ ./a.out
Please enter the price of a jar of peanut butter: 3.50
Please enter type of peanut butter: JIF
Please enter price of a jar of jelly: 4.00
Please enter the type of jelly: Welch's
Please enter the price of a loaf of bread: 3.00
How many slices of bread are there in a loaf: 30
Please enter the type of bread: WonderBread
The cost of JIF used is $0.175
The cost of Welch's is $0.4
The cost of WonderBread is $0.2
The cost of the sandwich is $0.775
Press any key to continue..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote