/*
Ask for an amount and whether it is taxable; calculate the sales tax and show the tax amount and the total including the tax.
using for loop
*/
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string x;
double amount, tax;
cout << "i will tell you your sales tax and your total.\n";
cout << "Is your product taxable? <y/n> \n";
cin >> x;
if ( x == "y")
{cout << "What is the cost of your product?";
cin >> cost;
for ( int cost ; cost > 0; cost * 1.0975)
amount = cost
tax = (cost / 1.0975 * .0975)
cout << "Your tax is $"
<< tax
<< " and your total is $ "
<< amount
<< endl;}
else
{cout << "Have a good day!\n";}
system ("pause");
}
I was wondering how to use retrieve the cost from the for loop and apply it outside? and is there a way to make the for loop only go once?
You're missing all sorts of stuff. Missing the beginning bracket after your for, not initializing the cost variable, missing semi colons.
Well actually I just saw your semi colon is going to that if, so that for loop is literally useless. All it does is sit there and change the value of amount as long as cost > 0. Why are you wanting a loop to go only once...?
siigh. ahha. i'm actually not sure how to do this project. :\ was doing this on a hunch . i'm supposed to take in a cost and give the tax ( 9.75%) and the total (tax plus cost) using a for loop.
You use loops like that if you want to repeat something. I'm sure what they meant was be able to have the user enter multiple items and get tax and total cost returned for each. You might have heard it before, but writing down an algorithm on paper, or flowchart or a diagram of some sort will help greatly. I can almost guarantee that once you see this written out on paper in english/psuedo-code it will seem trivial to you