c++ won't output the correct decimal...

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

#include <iostream>
#include <cmath>

using namespace std;

void tax(float r, double x, double y, float z)
{
		
	cout<<"Please input the cost of an item: ";
	cin>>x;
	cout<<"\n";
	y='.08';
	r='x*y';
	cout<<"Tax on most items today is 8% of the total cost."<<endl;
	cout<<x*y<<" is how much you will be taxed on that purchase."<<endl;
	cout<<" "<<endl;
	cout<<"The total cost after tax is, "<<floor((r+x)+0.5)<<endl;
}


int main()
{
	float r;
	double x;
	double y;
	float z;
	
	
	cout<<"======================================================\n";
	cout<<"|        WELCOME TO MY TEXT BASED TAX CALCULATOR     |"<<endl;
	cout<<"|                                                    |"<<endl;
	cout<<"| This calculator was written in c++ by John McCrary |"<<endl;
	cout<<"======================================================\n";
	
	tax(r, x, y, z);
	
	return 0;
}


the output is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

======================================================
|        WELCOME TO MY TEXT BASED TAX CALCULATOR     |
|                                                    |
| This calculator was written in c++ by John McCrary |
======================================================
Please input the cost of an item: 10

Tax on most items today is 8% of the total cost.
3.027e+07 is how much you will be taxed on that purchase.
 
The total cost after tax is, 7.8752e+06

(program exited with code: 0)
Press return to continue


and obviously (.08*10) + 10 doesn't equal 7.8752
You should stop putting single quotes around everything. A character in single quotes is a character literal.
Topic archived. No new replies allowed.