Here is the scenario:
Modify your code to check for valid input values. Specifically:
The Wholesale Cost must be positive. { I.e. not zero or negative }
The Mark-up Percentage must be positive but less than or equal to 100%.
The Sales Tax Rate ( Percentage ) must be positive but strictly less than 15%.
Use the most appropriate LOOP construct to get user input until a good value is given.
Be sure your code tells the user that the value entered was wrong, when it is invalid.
If a good value is given, do NOT say anything to the user. I.e. when a good value is given – move on.
Run your code multiple times using the input values I am giving on the next page
Part A ( Continued)
Use these input values for each run:
First run should enter all correct values:
Wholesale Cost: $100.00
Mark-up percentage: 8%
Sales tax rate: 3%
Second run
First enter an incorrect value for the wholesale cost – enter a NEGATIVE number,
then enter another incorrect value for the wholesale cost – enter a ZERO,
then enter another incorrect value for the wholesale cost – enter another NEGATIVE number,
then enter a correct wholesale cost of $50.00
Then give a NEGATIVE value for Mark-up percentage
then give a Mark-up percentage value of 200%
then a Mark-up percentage value of 10%
Finally a good value for Sales Tax Rate of 5%.
Third run
First you should enter a correct wholesale cost of $25.00
then a Mark-up percentage value of 100%
then a Sales Tax Rate of -5% ( NEGATIVE 5% )
then a Sales Tax Rate of 0% ( zero )
then a Sales Tax Rate of 15%
then a Sales Tax Rate of 20%
and finally a good value for Sales Tax Rate of 10%.
Here is my code please let me know what I am doing wrong. I do not understand what to do
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
using namespace std;
int main ()
{
cout <<"Rebecca Carolina Katz,lab #6 part A"<< endl;
// Variable Declarations
float Wholesale_Cost;
float Mark_up_percentage;
float Sales_tax_rate;
int prompt;
while ( (Wholesale_Cost < 0) && ( Mark_up_percentage > 0.100) && ( Sales_tax_rate < 0.15) )
{
cout << "Wholesale Cost:";
cin >> Wholesale_Cost > 0;
cout << "Mark-up percentage:";
cin >> Mark_up_percentage ;
cout << "Salestax Rate:";
cin >> Sales_tax_rate ;
cout << "Value entered not good";
cin >> prompt ;
cout << endl;
} // Assuming the values are good now
cout << "Wholesale Cost:";
cin >> Wholesale_Cost;
cout << "Mark-up percentage:";
cin >> Mark_up_percentage;
cout << "Salestax Rate:";
cin >> Sales_tax_rate;
return 0 ;
}
|