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.
#include <iostream>
#include <string>
usingnamespace 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
elseif( i >= 7550.01 && i <=30650)
r = ((i - 7550)*.15) + 755; // $755 plus 15% of the amount over 7,550
elseif( i >= 30650.01 && i <= 74200 )
r = ((i - 30650 )*.25 ) + 4220; // $4,220.00 plus 25% of the amount over 30,650
elseif( i >= 74200.01 && i <= 154800 )
r = ((i-74200) *.28) + 15107.50; // $15,107.50 plus 28% of the amount over 74,200
elseif( i >= 154800.01 && i <= 336550)
r = ((i-154800)*.33 ) + 37675.50; // $37,675.50 plus 33% of amount over 154,800
elseif (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 . . . */
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!