These are the guidelines;

1.
Create and initialize an array containing the following tax rates: 0%, 5%, 10%, 15%, and 20%. Create and initialize another array containing the following income amounts: 0, 10000, 20000, 50000, 100000.
2.
Prompt the user to enter a gross income amount. Read the gross income amount from the keyboard.
3.
Use a for loop to find the appropriate tax rate for the income amount. You will need to search the income array until you find the proper income "break". For example, if the user entered 5000, the tax rate would be 0% because element 0 in the income array contains the last amount smaller than the income and 0% is element 0 in the tax rate array. If the user entered 30000, the tax rate would be 10% because element 2 in the income array is the last entry smaller than the income and 10% is element 2 in the tax rate array. If the user entered 50000, the tax rate would be 15% because element 3 in the income array is the last entry smaller than the income and 15% is element 3 in the tax rate array. This can be summarized in the table below.


Income Tax Rate
$0 to $9,999

0%
$10,000 to $19,999

5%
$20,000 to $49,999

10%
$50,000 to $99,999

15%
$100,000 and higher

20%

4.
You cannot use a series of if/else statements as was done in short assignment 1. You must use a loop statement to search the array.
5.
Print the tax amount. The tax amount will be equal to the income amount times the tax rate. The tax rate must be divided by 100 to get the decimal equivalent. After printing the tax for one income amount, ask the user if he/she wants to continue. If so repeat the process. If not, stop the application.

#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <cctype>

int main(int argc, char *argv[])
{
double taxrate [] = {0, .05, .1, .15, .2};
double income [] = {0, 10000, 20000, 50000,100000};
double grossincome = 0;
double totalTax = 0;
char userresponse;

do
{
cout << "Enter the gross pay : ";
cin >> grossincome;

double rate = taxrate [4];
for (int i = 4; i >= 0 && income >= grossincome; --i)
{

rate = taxrate[i-1];
{
totalTax = grossincome * rate;
cout << "Taxes are : $" << totalTax << endl;
}
}

cout << "Enter Y or y to continue. Anything else to quit." << endl;
cin >> userresponse;
}
while (toupper(userresponse) == 'Y');

system ("PAUSE");
return 0;
}

The program prints multiple values how do I fix it???

I think I need to enter break; , but where??

Edited 6 Years Ago by MTW1989: n/a

our cout is inside of your for loop. That means it

inside of your for loop. That means it happens 4 times.

How would I remove the count from the loop so it will not caculate four times?

This question has already been answered. Start a new discussion instead.