473,388 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Program not running correctly

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,80 2 +
28%"<<"\t\t"<<"$25,350"<<endl;
cout <<"$61,400"<<"\t\t"<<"$128,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,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;
}
}
Jul 22 '05 #1
4 1198
D wrote:
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,80 2 +
28%"<<"\t\t"<<"$25,350"<<endl;
cout <<"$61,400"<<"\t\t"<<"$128,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,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...
}
}

--
Please remove capital As from my address when replying by mail
Jul 22 '05 #2
D wrote:
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
Jul 22 '05 #3
ure return shud b outside the while loop
vivek
Jul 22 '05 #4
vi*****@yahoo.com (slashman) wrote in message news:<44**************************@posting.google. com>...
ure return shud b outside the while loop
vivek


The official language of this group is english.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: parthan | last post by:
We are running our c++ program, which uses JNI, as Windows services. Program is getting CLASSPATH env variable correctly and also initializes JVM successfully. After initializing JVM, programs...
0
by: zhouhaiming | last post by:
On our test machine I can compile my c source code on AIX5.1(ML4) by "- q32" option and "OBJECT_MODE=32" environment variable, and it can correctly running. My operation system environment is:...
6
by: CJ | last post by:
Hey, I'm new to the Python world, but I do have experience in several other languages. I've been running through a tutorial, and I decided that I'd make a program that runs through a list, finds if...
4
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
10
by: jon | last post by:
I am a beginner C programmer, this is actually my first programming lanugage, besides html, cgi, and javascript. I am looking for a way to make an .exe file, or a copy of my own file. I have tried...
20
by: Francine.Neary | last post by:
I am learning C, having fun with strings & pointers at the moment! The following program is my solution to an exercise to take an input, strip the first word, and output the rest. It works fine...
20
by: Boki Digtal | last post by:
Hi All, How to limit the c# program can only run one instance at the same time ? Thank you! Best regards, Boki.
2
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
2
by: Tim Kelley | last post by:
I have an application that I have distributed using one click install. I selected the option to allow the program to be run if the server is offline. From another program I want to be able to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.