Program not running correctly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D

    Program not running correctly

    I'm new to C++ so please excuse the bad coding but I'm having problems
    getting my program to loop. It should continue to ask for more
    amounts and calculate them properly but it just iterates once and then
    finishes. Any suggestions would be appreciated. Here is what I have:

    #include <iostream>
    #include <iomanip>
    using namespace std;

    int main()
    {

    float percent,baseAmo unt,taxIncome,t axDue,lowerLimi t;

    cout <<setw(42) <<"TAX TABLE"<<endl;
    cout <<"Taxable Income"<<"\t\t\ t\t\t\t\t"<<"Of Amount"<<endl;
    cout <<"Over --"<<"\t\t"<< "But Not Over --"<<"\t\t"<<"You r Tax Is
    --"<<"\t\t"<<"Ove r--"<<endl;
    cout <<"$0"<<"\t\t"< <"$25,350"<<"\t \t\t"<<"$0 +
    15%"<<"\t\t"<<" $0"<<endl;
    cout <<"$25,350"<<"\ t\t"<<"$61,400" <<"\t\t\t"<<"$3 ,802 +
    28%"<<"\t\t"<<" $25,350"<<endl;
    cout <<"$61,400"<<"\ t\t"<<"$128,100 "<<"\t\t"<<"$13 ,896 +
    31%"<<"\t\t"<<" $61,400"<<endl;
    cout <<"$128,100"<<" \t"<<"$278,450" <<"\t\t"<<"$34, 573 +
    36%"<<"\t\t"<<" $128,100"<<endl ;
    cout <<"$278,450"<<" \t\t\t\t"<<"$86 ,699 +
    39.6%"<<"\t\t"< <"$278,450"<<en dl;
    cout <<"\n";
    cout <<setw(42) <<"TAX OUTPUT" <<endl;
    cout <<"Taxable Income" "\t\t\t" "Tax Due\n";
    cout <<"--------------" "\t\t\t" "-------\n";
    cout <<"?" "\t\t\t\t" "?\n";
    cout <<"?" "\t\t\t\t" "?\n";
    cout <<"?" "\t\t\t\t" "?\n";
    cout <<"?" "\t\t\t\t" "?\n";
    cout <<"?" "\t\t\t\t" "?\n";
    cout <<"\n";
    cout <<"I'm going to calculate your tax due based on your income.\n";
    cout <<"Your tax due will be using the Tax Table and then print out
    \n";
    cout <<"the results on the Output Table with your tax due amount.\n";
    cout <<"Please enter your taxable income in whole dollars.\n";
    cin >>taxIncome;
    while (taxIncome >=0)
    {

    if (taxIncome <=25,350)
    {
    baseAmount = 0;
    lowerLimit = 0;
    percent = 15;
    }
    else if (taxIncome <=61,400)
    {
    baseAmount = 3,802;
    lowerLimit = 35,350;
    percent = 28;
    }
    else if (taxIncome <=128,100)
    {
    baseAmount = 13,896;
    lowerLimit = 61,400;
    percent = 31;
    }
    else if (taxIncome <=278,450)
    {
    baseAmount = 34,573;
    lowerLimit = 128,100;
    percent = 36;
    }
    else
    {
    baseAmount = 86,699;
    lowerLimit = 278,450;
    percent = 39.6;
    }
    taxDue = baseAmount + (taxIncome - lowerLimit) * percent /100;
    cout <<"Here is your taxable income "<<taxIncom e <<endl;
    cout <<"And here is your tax due "<<taxDue<<endl ;
    cout <<"Please enter your next amount\n";
    cin>>taxIncome;
    return 0;
    }
    }
  • Victor Bazarov

    #2
    Re: Program not running correctly

    D wrote:
    [color=blue]
    > I'm new to C++ so please excuse the bad coding but I'm having problems
    > getting my program to loop. It should continue to ask for more
    > amounts and calculate them properly but it just iterates once and then
    > finishes. Any suggestions would be appreciated. Here is what I have:
    >
    > #include <iostream>
    > #include <iomanip>
    > using namespace std;
    >
    > int main()
    > {
    >
    > float percent,baseAmo unt,taxIncome,t axDue,lowerLimi t;
    >
    > cout <<setw(42) <<"TAX TABLE"<<endl;
    > cout <<"Taxable Income"<<"\t\t\ t\t\t\t\t"<<"Of Amount"<<endl;
    > cout <<"Over --"<<"\t\t"<< "But Not Over --"<<"\t\t"<<"You r Tax Is
    > --"<<"\t\t"<<"Ove r--"<<endl;
    > cout <<"$0"<<"\t\t"< <"$25,350"<<"\t \t\t"<<"$0 +
    > 15%"<<"\t\t"<<" $0"<<endl;
    > cout <<"$25,350"<<"\ t\t"<<"$61,400" <<"\t\t\t"<<"$3 ,802 +
    > 28%"<<"\t\t"<<" $25,350"<<endl;
    > cout <<"$61,400"<<"\ t\t"<<"$128,100 "<<"\t\t"<<"$13 ,896 +
    > 31%"<<"\t\t"<<" $61,400"<<endl;
    > cout <<"$128,100"<<" \t"<<"$278,450" <<"\t\t"<<"$34, 573 +
    > 36%"<<"\t\t"<<" $128,100"<<endl ;
    > cout <<"$278,450"<<" \t\t\t\t"<<"$86 ,699 +
    > 39.6%"<<"\t\t"< <"$278,450"<<en dl;
    > cout <<"\n";
    > cout <<setw(42) <<"TAX OUTPUT" <<endl;
    > cout <<"Taxable Income" "\t\t\t" "Tax Due\n";
    > cout <<"--------------" "\t\t\t" "-------\n";
    > cout <<"?" "\t\t\t\t" "?\n";
    > cout <<"?" "\t\t\t\t" "?\n";
    > cout <<"?" "\t\t\t\t" "?\n";
    > cout <<"?" "\t\t\t\t" "?\n";
    > cout <<"?" "\t\t\t\t" "?\n";
    > cout <<"\n";
    > cout <<"I'm going to calculate your tax due based on your income.\n";
    > cout <<"Your tax due will be using the Tax Table and then print out
    > \n";
    > cout <<"the results on the Output Table with your tax due amount.\n";
    > cout <<"Please enter your taxable income in whole dollars.\n";
    > cin >>taxIncome;
    > while (taxIncome >=0)
    > {
    >
    > if (taxIncome <=25,350)
    > {
    > baseAmount = 0;
    > lowerLimit = 0;
    > percent = 15;
    > }
    > else if (taxIncome <=61,400)
    > {
    > baseAmount = 3,802;
    > lowerLimit = 35,350;
    > percent = 28;
    > }
    > else if (taxIncome <=128,100)
    > {
    > baseAmount = 13,896;
    > lowerLimit = 61,400;
    > percent = 31;
    > }
    > else if (taxIncome <=278,450)
    > {
    > baseAmount = 34,573;
    > lowerLimit = 128,100;
    > percent = 36;
    > }
    > else
    > {
    > baseAmount = 86,699;
    > lowerLimit = 278,450;
    > percent = 39.6;
    > }
    > taxDue = baseAmount + (taxIncome - lowerLimit) * percent /100;
    > cout <<"Here is your taxable income "<<taxIncom e <<endl;
    > cout <<"And here is your tax due "<<taxDue<<endl ;
    > cout <<"Please enter your next amount\n";
    > cin>>taxIncome;
    > return 0;[/color]

    Remove this 'return', and maybe it will go on...
    [color=blue]
    > }
    > }[/color]


    --
    Please remove capital As from my address when replying by mail

    Comment

    • E. Robert Tisdale

      #3
      Re: Program not running correctly

      D wrote:
      [color=blue]
      > I'm new to C++ so please excuse the bad coding but I'm having problems
      > getting my program to loop. It should continue to ask for more
      > amounts and calculate them properly but it just iterates once and then
      > finishes. Any suggestions would be appreciated. Here is what I have:
      >[/color]
      [color=blue]
      > cat main.cc[/color]
      #include <iostream>
      #include <iomanip>

      int main() {
      // using namespace std;
      using std::cin; using std::cout; using std::endl; using std::setw;


      cout << setw(42) << "TAX TABLE" << endl;
      cout << "Taxable Income\t\t\t\t\ t\t\tOf Amount" << endl;
      cout << "Over --\t\tBut Not Over --\t\t"
      "Your Tax Is --\t\tOver--" << endl;
      cout << "$0\t\t$25,350\ t\t\t$0 + 15%\t\t$0" << endl;
      cout << "$25,350\t\t$61 ,400\t\t\t$3,80 2 + 28%\t\t$25,350" << endl;
      cout << "$61,400\t\t$12 8,100\t\t$13,89 6 + 31%\t\t$61,400" << endl;
      cout << "$128,100\t$278 ,450\t\t$34,573 + 36%\t\t$128,100 " << endl;
      cout << "$278,450\t\t\t \t$86,699 + 39.6%\t\t$278,4 50" << endl;
      cout << endl;
      cout << setw(42) << "TAX OUTPUT" << endl;
      cout << "Taxable Income" "\t\t\t" "Tax Due\n";
      cout << "--------------" "\t\t\t" "-------\n";
      cout << "?" "\t\t\t\t" "?" << endl;
      cout << "?" "\t\t\t\t" "?" << endl;
      cout << "?" "\t\t\t\t" "?" << endl;
      cout << "?" "\t\t\t\t" "?" << endl;
      cout << "?" "\t\t\t\t" "?" << endl;
      cout << endl;
      cout << "I'm going to calculate your tax due based on your income."
      << endl; cout << "Your tax due will be using the Tax Table and then
      print out" << endl; cout << "the results on the Output Table with your
      tax due amount." << endl; cout << "Please enter your taxable income
      in whole dollars." << endl; float taxIncome = 0.00;
      cin >> taxIncome;
      while (0 <= taxIncome) {
      float baseAmount = 0.00, lowerLimit = 0.00, percent = 0.00;

      if (taxIncome <= 25350.00) {
      baseAmount = 0.00;
      lowerLimit = 0.00;
      percent = 15.00;
      }
      else
      if (taxIncome <= 61400.00) {
      baseAmount = 3802.00;
      lowerLimit = 35350.00;
      percent = 28.00;
      }
      else
      if (taxIncome <= 128100.00) {
      baseAmount = 13896.00;
      lowerLimit = 61400.00;
      percent = 31.00;
      }
      else
      if (taxIncome <= 278450.00) {
      baseAmount = 34573.00;
      lowerLimit = 128100.00;
      percent = 36.00;
      }
      else {
      baseAmount = 86699.00;
      lowerLimit = 278450.00;
      percent = 39.6;
      }
      float taxDue = baseAmount + (taxIncome - lowerLimit)*per cent/100;
      cout << "Here is your taxable income $" << taxIncome << endl;
      cout << "And here is your tax due $" << taxDue << endl;
      cout <<"Please enter your next amount" << endl;
      cin >> taxIncome;
      }
      return 0;
      }
      [color=blue]
      > g++ -Wall -ansi -pedantic -o main main.cc
      > ./main[/color]
      TAX TABLE
      Taxable Income Of Amount
      Over -- But Not Over -- Your Tax Is -- Over--
      $0 $25,350 $0 + 15% $0
      $25,350 $61,400 $3,802 + 28% $25,350
      $61,400 $128,100 $13,896 + 31% $61,400
      $128,100 $278,450 $34,573 + 36% $128,100
      $278,450 $86,699 + 39.6% $278,450

      TAX OUTPUT
      Taxable Income Tax Due
      -------------- -------
      ? ?
      ? ?
      ? ?
      ? ?
      ? ?

      I'm going to calculate your tax due based on your income.
      Your tax due will be using the Tax Table and then print out
      the results on the Output Table with your tax due amount.
      Please enter your taxable income in whole dollars.
      130000
      Here is your taxable income $130000
      And here is your tax due $35257
      Please enter your next amount
      -1

      Comment

      • slashman

        #4
        Re: Program not running correctly

        ure return shud b outside the while loop
        vivek

        Comment

        • Dan Cernat

          #5
          Re: Program not running correctly

          viv_men@yahoo.c om (slashman) wrote in message news:<44e14dcd. 0411101946.33d6 bdae@posting.go ogle.com>...[color=blue]
          > ure return shud b outside the while loop
          > vivek[/color]

          The official language of this group is english.

          Comment

          Working...