Program not running correctly

D

D

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,baseAmount,taxIncome,taxDue,lowerLimit;

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"<<"Your Tax Is
--"<<"\t\t"<<"Over--"<<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"<<endl;
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 "<<taxIncome <<endl;
cout <<"And here is your tax due "<<taxDue<<endl;
cout <<"Please enter your next amount\n";
cin>>taxIncome;
return 0;
}
}
 
V

Victor Bazarov

D said:
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,baseAmount,taxIncome,taxDue,lowerLimit;

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"<<"Your Tax Is
--"<<"\t\t"<<"Over--"<<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"<<endl;
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 "<<taxIncome <<endl;
cout <<"And here is your tax due "<<taxDue<<endl;
cout <<"Please enter your next amount\n";
cin>>taxIncome;
return 0;

Remove this 'return', and maybe it will go on...
 
E

E. Robert Tisdale

D said:
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:
cat main.cc
#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,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" << 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)*percent/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;
}
g++ -Wall -ansi -pedantic -o main main.cc
./main
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top