for statement problem

Heyy, so here's my code
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
/*
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>
using namespace 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...?

This needs some cleaning
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
:OO i think i get it! i hope.. :c sorry! but,
the loop would be for each individual product/person right?

so would the gist of it be like..
1
2
3
4
5
int numberofproducts
cin >> numberofproducts

for ( int cost; numberofproducts > 0 ;  )
{ cost * 1.0975 } 


would that be the general form? sorry. i'm utterly completely new at coding.. i should've takin CIS 6 before CIS25 but its too late now..


Topic archived. No new replies allowed.