Invalid calculation?
This is a program for my school class. When I input $30,000, I always get -$9,107 or something like that. What am I doing wrong??
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#include <iostream>
#include <iomanip>
#include <string>
#include <stdlib.h>
#include <math.h>
using namespace std;
float taxableincome;
float takeout1;
float takeout2;
float takeout3;
float taxpercent;
float totaltax = 0.0;
void Input();
float Calc();
void Display();
int main()
{
int x;
Input();
Calc();
Display();
cin >> x;
return 0;
}
void Input()
{
cout << "What is amount of taxable income\?" << endl;
cin >> taxableincome;
system("cls");
}
float Calc()
{
if (taxableincome > 0 && taxableincome <= 24650)
{
takeout1 = 0;
takeout2 = taxableincome - 0;
taxpercent = .15;
takeout3 = takeout2 * taxpercent;
totaltax = takeout1 + takeout3;
}
if (taxableincome > 24650 && taxableincome <= 59750)
{
takeout1 = 3697.5;
takeout2 = taxableincome - 24650;
taxpercent = .28;
takeout3 = takeout2 * taxpercent;
totaltax = takeout1 + takeout3;
}
if (taxableincome > 59750 && taxableincome <= 124650)
{
takeout1 = 13525.5;
takeout2 = taxableincome - 59750;
taxpercent = .31;
takeout3 = takeout2 * taxpercent;
totaltax = takeout1 + takeout3;
}
if (taxableincome > 124650 && taxableincome <= 271050)
{
takeout1 = 33644.5;
takeout2 = taxableincome - 124650;
taxpercent = .36;
takeout3 = takeout2 * taxpercent;
totaltax = takeout1 + takeout3;
}
if (taxableincome < 271050)
{
takeout1 = 86348.5;
takeout2 = taxableincome - 271050;
taxpercent = .396;
takeout3 = takeout2 * taxpercent;
totaltax = takeout1 + takeout3;
}
return totaltax;
}
void Display()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "With a taxable income of $" << taxableincome << " is $" << totaltax << "." << endl;
}
|
Is this last condition supposed to be > and not <?
if (taxableincome < 271050)
I've changed that, and it works perfectly. I CAN NOT believe I missed that. Pretty nooby mistake, haha. Thanks a bunch!
Topic archived. No new replies allowed.