Can't figure out why I am getting this error while testing.

I am working on an assignment for school and while testing this short program to determine tax rates on a particular income I run into problems when trying to test amounts over 74,200. I am getting a message popping up that "says runtime error variable r not declared." I know it must be that area of the code but cant quite figure it out.

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  #include <iostream>
#include <string>
using namespace std;
double tax_Owed(double); // prototype header for taxes owed

void main(void) //driver for input and testing
{
	double x;
	cout<< "Enter the income for a single person: ";
	cin>>x;
	//cout.setf(ios::fixed); //using standard notation instead of scientific
	//cout.setf(ios::showpoint);
	//cout.precision(2); //limiting precision number to two 
	cout<<"Total amount of taxes owed: $"<< tax_Owed(x) <<endl; //output of total amount of taxes owed
	cout<<endl;
		

return;
} // end main


double tax_Owed(double i )//function header
{
	double r ; 

	if( i > 0 && i <= 7550)
		{r=  (i * .10); // 10% over amount over $0

	else if( i >= 7550.01 && i <=30650) 
		r = ((i - 7550)*.15) + 755; // $755 plus 15% of the amount over 7,550

	else if( i >= 30650.01 && i <= 74200 )
		r = ((i - 30650 )*.25 ) + 4220; // $4,220.00 plus 25% of the amount over 30,650 

	else if( i >= 74200.01 && i <= 154800 )
		r = ((i-74200) *.28) + 15107.50; // $15,107.50 plus 28% of the amount over 74,200

	else if( i >= 154800.01 && i <= 336550)
		r = ((i-154800)*.33 ) + 37675.50; // $37,675.50 plus 33% of amount over 154,800

	else if (i >= 336550.01)// if the amount is over $336,550 with no limit this is enacted
		r = ((i-336550)*.35) + 97653;  // $97,653.00 plus 35% of the amount over 336,550
		
	
return r;
} 

/*
test 1
--------------------------------------------
Enter the income for a single person: 1000
Total amount of taxes owed: $100.00

Press any key to continue . . .

test 2
--------------------------------------------
Enter the income for a single person: 10000
Total amount of taxes owed: $1122.50

Press any key to continue . . .

test 3
--------------------------------------------
Enter the income for a single person: 36000
Total amount of taxes owed: $5557.50

Press any key to continue . . . */
Your line 27 {r= (i * .10); // 10% over amount over $0
remove { and it should fix it.
Last edited on
I got that taken out, but didn't seem to do the trick. Still getting runtime error when I test $75,000.
* I take that back, it seemed there was something wrong with the way I had the file opened. Got it figured out. Thanks!
Last edited on
Topic archived. No new replies allowed.