using if ___ else statement and switch case statement for each problem.
-Question 1
The Last Stop Boutique is having a five-day sale. Each day, starting on Monday, the price will drop 10% of the previous day’s price. For example, if the original price of a product is $20.00, the sale on Monday would be $18.00 (10% less than the original price).
On Tuesday the sale price would be $16.20 (10% less than Monday)
On Wednesday - $14.58.
On Thursday - $13.12.
On Friday - $11.81.
Develop a solution that will calculate the price of an item for each of the five days, given the original price. Test the solution for an item costing $10.00.
-Question 2
Make changes in the solution to problem 1 to SET the price at wholesale when the sale price drops below the wholesale price. Test the solution with the following prices:
Retail price: $20.00 & $25.00
Wholesale price: $10.00 & $20.00
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "****Question 1****" << endl;
double price = 0;
cout << "Enter initial price: ";
cin >> price;
cout << fixed << setprecision(2);
for (int i = 0; i < 5; i++)
{
switch (i)
{
case 0:
{
price *= 0.9;
cout << "On Monday - $" << price << endl;
break;
}
case 1:
{
price *= 0.9;
cout << "On Tuesday - $" << price << endl;
break;
}
case 2:
{
price *= 0.9;
cout << "On Wednesday - $" << price << endl;
break;
}
case 3:
{
price *= 0.9;
cout << "On Thursday - $" << price << endl;
break;
}
case 4:
{
price *= 0.9;
cout << "On Friday - $" << price << endl;
break;
}
default:
break;
}
}
cout << "****Question 2****" << endl;
cout << "Enter retail price: ";
cin >> price;
double wholesale = 0;
cout << "Enter wholesale price: ";
cin >> wholesale;
cout << fixed << setprecision(2);
for (int i = 0; i < 5; i++)
{
switch (i)
{
case 0:
{
if (price * 0.9 > wholesale) price *= 0.9;
else price = wholesale;
cout << "On Monday - $" << price << endl;
break;
}
case 1:
{
if (price * 0.9 > wholesale) price *= 0.9;
else price = wholesale;
cout << "On Tuesday - $" << price << endl;
break;
}
case 2:
{
if (price * 0.9 > wholesale) price *= 0.9;
else price = wholesale;
cout << "On Wednesday - $" << price << endl;
break;
}
case 3:
{
if (price * 0.9 > wholesale) price *= 0.9;
else price = wholesale;
cout << "On Thursday - $" << price << endl;
break;
}
case 4:
{
if (price * 0.9 > wholesale) price *= 0.9;
else price = wholesale;
cout << "On Friday - $" << price << endl;
break;
}
default:
break;
}
}
return 0;
}
Comments
Leave a comment