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
#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;}
Comments
Leave a comment