Oct 22, 2011 at 9:54pm UTC
First time programmer here. Maybe I am going about this the wrong way, but I am trying to figure out how to fill in the rest of the table. Here is the code:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
double s,
t;
cout << setprecision(2)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint);
cout << " Amount Tax Rate" << endl;
cout << " ---------------------------------------------------------------------" << endl;
cout << " 4.0% 4.5% 5.0% 5.5% 6.0% 6.5% 7.0%" << endl;
cout << endl;
{
for (t = .04; t <= .07; t += .05)
for (s = 100; s <= 1000; s += 100)
cout << " " << setw(10) << s << setw (10) << t * s << endl;
}
return 0;
}
Oct 22, 2011 at 11:38pm UTC
I understand why you're doing the for loops the way you are, but the way you're handling it is confusing you.
for (t = .04; t <= .07; t += .05)
This will only fire once, you're increasing it by 5%. It should read, if I'm understanding the intent properly:
for (t = .04; t <= .07; t += .005)
With this, it will increase the tax by 0.5% per iteration, allowing you to calculate the 4.5%, 5.0%, 5.5%, etc tax brackets.
This is why you
increment counters and
calculate variables .
1 2 3 4 5 6 7 8
const int s = 100;
double t[7] = {.04, .045, .05, .055, .06, .065, .07};
for (int i = 0; i < 7; i++){
for (int j = 1; j <= 10; j++){
cout << " " << setw(10) << s * j << setw(10) << t[i] * (s * j) << endl;
}
}
Last edited on Oct 22, 2011 at 11:39pm UTC
Oct 23, 2011 at 1:14am UTC
Thank you. For some reason the program is calculating but the output is not a table form? any suggestions?
Oct 23, 2011 at 1:23am UTC
Try this:
cout << " " << setw(10) << s * j << setw(10) << t[i] * (s * j) << "\n" ;
Oct 23, 2011 at 3:15am UTC
Post what you're getting and what you're looking for.
Oct 23, 2011 at 3:45am UTC
this is the current output:
Amount Tax Rate
---------------------------------------------------------------------
4.0% 4.5% 5.0% 5.5% 6.0% 6.5% 7.0%
100 4.00
200 8.00
300 12.00
400 16.00
500 20.00
600 24.00
700 28.00
800 32.00
900 36.00
1000 40.00
100 4.50
200 9.00
300 13.50
400 18.00
500 22.50
600 27.00
700 31.50
800 36.00
900 40.50
1000 45.00
100 5.00
200 10.00
300 15.00
400 20.00
500 25.00
600 30.00
700 35.00
800 40.00
900 45.00
1000 50.00
100 5.50
200 11.00
300 16.50
400 22.00
500 27.50
600 33.00
700 38.50
800 44.00
900 49.50
1000 55.00
100 6.00
200 12.00
300 18.00
400 24.00
500 30.00
600 36.00
700 42.00
800 48.00
900 54.00
1000 60.00
100 6.50
200 13.00
300 19.50
400 26.00
500 32.50
600 39.00
700 45.50
800 52.00
900 58.50
1000 65.00
100 7.00
200 14.00
300 21.00
400 28.00
500 35.00
600 42.00
700 49.00
800 56.00
900 63.00
1000 70.00
This is what I need, not going to fill in the whole table. I hope you get the idea.
Amount Tax Rate
---------------------------------------------------------------------
4.0% 4.5% 5.0% 5.5% 6.0% 6.5% 7.0%
100 4.00 4.50 5.0 5.5
200 8.00
300 12.00
400 16.00
500 20.00
600 24.00
700 28.00
800 32.00
900 36.00
1000 40.00
Oct 23, 2011 at 3:47am UTC
I do get the idea; you set your for loops backwards.
1 2 3 4 5 6 7 8 9 10
const int s = 100;
double t[7] = {.04, .045, .05, .055, .06, .065, .07};
for (int j = 1; j <= 10; i++){
cout << "" << setw(10) << s * j;
for (int i = 0; i < 7; j++){
cout << " " << setw(10) << t[i] * (s * j);
}
cout << endl;
}
Last edited on Oct 23, 2011 at 3:49am UTC