log table

Hello everyone, I am working on an assignment to print out a table of log values. I am very close to the provided solution but there are a few bugs in my program that I cannot figure out.

This is my output:
Table starts at logarithm of b = 2 with base a = 3
Log values b + 0 b + 1 b + 2 b + 3 b + 4
a + 06 0.632 12 1.32 1.52 1.6
a + 12 0.52 0.792 12 1.22 1.3
a + 22 0.432 0.682 0.862 12 1.1
a + 32 0.392 0.612 0.772 0.92 1

This is the provided solution.
Table starts at logarithm of b = 2 with base a = 3
Log values b + 0 b + 1 b + 2 b + 3 b + 4
a + 0 0.63 1.00 1.26 1.46 1.63
a + 1 0.50 0.79 1.00 1.16 1.29
a + 2 0.43 0.68 0.86 1.00 1.11
a + 3 0.39 0.61 0.77 0.90 1.00

For some reason the first column of "a + " values have an extra number at the end, and where there should be values of 1.00 there are 12's in my table. Also, how do I get each value to display two decimals? Thank you, any help is appreciated!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
int a, b, base, values, p;

cout << "Enter start value for base a: ";
cin >> a;
cout << "Enter how many base values: ";
cin >> base;
cout << "Enter start value for b: ";
cin >> b;
cout << "Enter how many b values: ";
cin >> values;
cout << "Enter precision: ";
cin >> p;

cout << endl << "Table starts at logarithm of b = " << b << " with base a = " << a << endl;

cout << "Log values ";

for (int i=0; i!=base+1; i++) {
	cout << setw(10) << "b + " << i;
}

cout << endl;

for (int j=0; j!=a+1; j++){
	cout << setw(10) << "a + " << j;
	for (int k=0; k!=values; k++){
		cout << cout.precision(p) << setw(10) << (log10(b+k)/log10(a+j));
}
cout << endl;
}
return (0);
}



1. It is enough to set precision on stream once.
2. http://www.cplusplus.com/reference/ios/fixed/
Topic archived. No new replies allowed.