Answer to Question #260670 in Java | JSP | JSF for Minenhle

Question #260670

A bagel shop charges 75 cents per bagel for orders of less than a half-dozen bagels and 50 cents per bagel for orders of a half-dozen or more. Write a program that requests the number of bagels ordered and displays the price for each bagel and the total cost. Format the output results with two decimal places


1
Expert's answer
2021-11-03T08:16:19-0400
#include <iostream>
#include <iomanip>
using namespace std;
// constants
const int HALF_DOZEN = 6;
const double PRICE = 0.75;
const double LOW_PRICE = 0.50;
int main()
{
int number_of_bagels; // the number of bagels odered
double total_price;
double 
price_per_bagel = PRICE;
// read the input
cout << "Enter the number of bagels ordered: ";
cin >> number_of_bagels;
// define the price per bagle
if (number_of_bagels >= HALF_DOZEN) {
price_per_bagel = LOW_PRICE;
}
// calculate the total price
total_price = price_per_bagel * number_of_bagels;
// output results
cout << fixed << setprecision(2); // set output format for doubles with 2 decimal places
cout << "Price for each bagel: " << price_per_bagel << endl;
cout << "Total price: " << total
_price << endl;
return 0;}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS