So my issue is that I am trying to create a tax program that gets a user input for income, status, and then prints out the results. I can get that all done with no errors. Once I try to get it inside of a while loop that will prompt the user "Do you want to calculate again?" the user can input y/n. "n" finishing the program and "y" needs to repeat the program and the user inputs information again and so on. I can't get the program to let the user input new values in for the variables. It will repeat the results only. Can someone help me with figuring that out? I have tried everything I can and have checked where I can and what others do, doesn't work for me. Any help is appreciated!
#include <iostream>
#include <string>
using namespace std;
double income, incomeTax;
char maritalStatus;
char again = 'Y';
int main() {
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
income = -1;
//Taxable Singles
const double ts1 = 863;
const double ts2 = 2588;
const double ts3 = 4313;
//Taxable Marriage
const double tm1 = 1726;
const double tm2 = 5176;
const double tm3 = 8626;
//Tax Rates
const double tr1 = .023;
const double tr2 = .033;
const double tr3 = .052;
const double tr4 = .075;
double t1, t2, t3;
//Add variable
const double as1 = 25, as2 = 85, as3 = 181;
const double am1 = 40, am2 = 175, am3 = 390;
//Addition variable simplified
double a1, a2, a3;
//const strings
const string s = "single", m = "joint";
string status;
int i = 0;
//Beginning of Loop
while (again == 'y' || again == 'Y') {
while (income < 0) {
cout << "Please enter your taxable Income." << "\n (This must be a positive value): " << endl;
cin >> income;
if (cin.fail() || income < 0) {
cout << "Please try again. Needs to be a positive number." << endl;
cin.clear();
cin.ignore(40, '\n');
income = -1;
}
}
while (maritalStatus == false) {
cout << "Please enter m if married and filing joint return," <<
"\n or s if filing a single return: ";
cin >> maritalStatus;
if (maritalStatus != 's' && maritalStatus != 'm') {
cout << "Please try again. Needs to be a 's' or 'm'." << endl;
cin.clear();
cin.ignore(40, '\n');
maritalStatus = false;
}
}
if (maritalStatus == 's') {
t1 = ts1;
t2 = ts2;
t3 = ts3;
a1 = as1;
a2 = as2;
a3 = as3;
status = s;
}
else if (maritalStatus == 'm') {
t1 = tm1;
t2 = tm2;
t3 = tm3;
a1 = am1;
a2 = am2;
a3 = am3;
status = m;
}
if (income > 0 && income <= t1) {
incomeTax = (income - (0)) * tr1;
}
else if (income > t1 && income <= t2) {
incomeTax = (income - (t1 - 1)) * tr2 + a1;
}
else if (income > t2 && income <= t3) {
incomeTax = (income - (t2 - 1)) * tr3 + a2;
}
else if (income > t3) {
incomeTax = (income - (t3 - 1)) * tr4 + a3;
}
cout << "Your taxable income is " << "$" << income << endl;
cout << "and you're filing a" << status << " return." << endl;
cout << "Your income tax will be " << "$" << incomeTax << endl;
cout << "Go again? (y/n) ";
cin >> again; //change control variable
}// end loop
system("pause");
return 0;
}