# I need help with my lab in C++

so im stuck and the teacher refuses to give assistance when i ask her for help she just say im not giving you the answers. wot even stear me in the right direction

so this is my code and out put

/Lab 6

# include

using namespace std;

int main ()
{
double Cost;
double Markup;
double Sales_Tax;

``````double Tax;
double Markup_Rate;
double Total_Cost;
double Markup_Percent;
double Sales_Tax_Percent;

cout << "My name\n\n\n" << endl;

do{

cout << "\nWhat is the cost of the book? \$";
cin >> Cost;
}while(Cost<0);

cout <<"Invalid entry must be greater than 0. ";

do{

cout << "What is the markup percentage? ";
cin >> Markup_Rate;
}while((Markup_Rate<0) && (Markup_Rate<=100));

cout <<"Invalid entry must be between 1 and 100";

do{

cout << "What is the sales tax rate? ";
cin >> Sales_Tax;
}while((Sales_Tax<0)&&(Sales_Tax<=0.15));

cout <<"Invalid entry must be Greater than 0 but less than .15";

Markup= Cost*Markup_Rate;
Tax= (Markup+Cost)*Sales_Tax;
Total_Cost= Markup+Tax+Cost;
Markup_Percent = Markup_Rate*100;
Sales_Tax_Percent = Sales_Tax*100;

cout << setw(2)<< fixed << setprecision(2) << "\nThe Wholesale cost is \$" <<Cost<< endl;
cout << setw(2)<< fixed << setprecision(0) <<"The markup Rate is " << Markup_Percent << "%" << endl;
cout << setw(2)<< fixed << setprecision(0) << " The sales tax rate is " << Sales_Tax_Percent<< "%" << endl;

cout << setw(2) << fixed << setprecision(2) << "\nMarkup Amount: \$" << Markup << endl;
cout << setw(2) << fixed << setprecision(2) << "Sales Tax Amount: \$" << Tax << endl;
cout << setw(2) << fixed << setprecision(2) <<"Total Cost of Book to customer: \$" << Total_Cost << endl;``````

return 0;
} so basicaly this is what im supposed to do

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.

part b of the lab will be to ask user to run the code again(without having to re launch program) but i should be able to do that on my own but would apreciate being pointed in the right directionor give me any helpfull tips with out giving me the answer

my code does what it supposed to do as far as validating wether the person enetered valid data

i just cant seem to get it to format correctly the lines keep running into eah other how do i get it to format correctly on the command prompt
code works but if i enter wrong num it doesnt say that i entered wrong number till after inputing the corect num

look closely here and anywhere else that has similar checks. less than 0 and less than/equal to 100...

}while((Markup_Rate<0) && (Markup_Rate<=100));

obvious error

1 Like

Here the cout about the invalid entry must be inside the cycle with an if condition else the message is always shown even if the value is valid. Also the message and the cycle are not compatible on the message you say greater than 0, but the cycle accepts the value 0. This solves the:

Here you made a mistake, this condition is the same as Markup_Rate<=100; And again the message about invalid input is always shown.

Same here

If you apply the changes that I told you I think the format will be corrected.

PS: My suggestion is to always put \n after printing out a string, makes things easier to look at.

If you have any more question I would be happy to help.