There is something wrong with this program. The code is ok, the program runs, but it stops after asking the user how much their income is. Where am I going wrong? (Sorry, it's really long, but I can't figure out where the problem is)

#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>

using namespace std;

double percent(double,int,int,int,int,int);
double tax(double,int,int,int,int,int);
bool isvalid(string);

int main ()
{
    cout << "If you are filing taxes as a single, enter s.\n";
           cout << "If you are filing taxes as married filing jointly, enter mj.\n";
           cout << "If you are filing taxes as married filing separately, enter ms.\n";

           string method;
           string s, mj, ms;
           cin >> method;

    cout << "What is your total taxable income? ";
    string total;
    cin >> total;

    while (!isvalid(total))
           {
               if (isvalid(total))
               {
                   cout << "The income is valid." << endl;
               }
               else 
               {
                   cout << "The income entered is invalid. Please enter a valid amount.";
                   cin >> total;
               }

           }

    double income;
    income=atof(total.c_str());    

    if (method==s)
    {
        cout << "Percentage Bracket: " << percent(income,8375,34000,82400,171850,373650) << "%" << endl;
        cout << "Income Tax: $" << tax(income,8375,34000,82400,171850,373650) << endl;
        cout << fixed << setprecision(2) << "Actual Percentage of Tax: " << (tax(income,8375,34000,82400,171850,373650)/income)*100 << "%" << endl;
    }

    else if (method==mj)
    {
        cout << "Percentage Bracket: " << percent(income,16750,68000,137300,209250,373650) << "%" << endl;
        cout << "Income Tax: $" << tax(income,16750,68000,137300,209250,373650) << endl;
        cout << fixed << setprecision(2) << "Actual Percentage of Tax: " << (tax(income,16750,68000,137300,209250,373650)/income)*100 << "%" << endl;       
    }

    else if (method==ms)
    {
        cout << "Percentage Bracket: " << percent(income,8375,34000,68650,104625,186825) << "%" << endl;
        cout << "Income Tax: $" << tax(income,8375,34000,68650,104625,186825) << endl;
        cout << fixed << setprecision(2) << "Actual Percentage of Tax: " << (tax(income,8375,34000,68650,104625,186825)/income)*100 << "%" << endl;     
    }

    return 0;
}

bool isvalid(string str)
{
    int first=0;
    if (str.length()==0) return false;
    if (str.at(0)=='-') return false;
    if (str.length() && str.at(first)==0) return false;
    for (int i=first; i<str.length(); i++)
    {
        if (!isdigit(str.at(i))) return false;
    }

    return true;
}

double percent(double x,int c1,int c2,int c3,int c4,int c5)
{
    double b;
    if (x<c1)
    {
        b=10;
    }
    else if (x<c2)
    {
        b=15;
    }
    else if (x<c3)
    {
        b=25;
    }
    else if (x<c4)
    {
        b=28;
    }
    else if (x<c5)
    {
        b=33;
    }
    else 
    {
        b=35;
    }

    return b;
}          
double tax(double x,int c1,int c2,int c3,int c4,int c5)
{
    double tax;
    if (x<c1)
    {
        tax=.1*x;
    }
    else if (x<c2)
    {
        tax=(.1*c1)+(.15*(x-c1));
    }
    else if (x<c3)
    {
        tax=(.1*c1)+(.15*(c2-c1))+(.25*(x-c2));
    }
    else if (x<c4)
    {
        tax=(.1*c1)+(.15*(c2-c1))+(.25*(c3-c2))+(.28*(x-c3));
    }
    else if (x<c5)
    {
        tax=(.1*c1)+(.15*(c2-c1))+(.25*(c3-c2))+(.28*(c4-c3))+(.33*(x-c4));
    }
    else 
    {
        tax=(.1*c1)+(.15*(c2-c1))+(.25*(c3-c2))+(.28*(c4-c3))+(.33*(c5-c4))+(.35*(x-c5));
    }

    return tax;
}

Forget it. I figured it out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.