Help fixing code please (aligning numbers)

I need help aligning my data, so far i'm getting everything lined up its just in my hyperbolic functions instead of .01 it will show .0100000000, how do i adjust this while still keeping my result to 10 value places

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
//This program calculates the values of several hyperbolic functions

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
	cout << "Hyperbolic Generator" << endl;

	double x;

	cout << endl;
	cout << "Enter a value to be converted to multiple Hyperbolic Funtions before your eyes" << endl;
	cin >> x;
	cout << endl;
	cout << "Converting: " << x << endl;
	cout << endl;

	double e = 2.71828182846;

	double minus = pow(e, x) - pow(e, -x);
	double plus = pow(e, x) + pow(e, -x);

	cout << setprecision(10) << "sinh(" << x << ") = " << fixed << setw(16) << minus / 2 << endl;
	cout << setprecision(10) << "cosh(" << x << ") = " << fixed << setw(16) << plus / 2 << endl;
	cout << setprecision(10) << "tanh(" << x << ") = " << fixed << setw(16) << minus / plus << endl;
	cout << setprecision(10) << "coth(" << x << ") = " << fixed << setw(16) << plus / minus << endl;
	cout << setprecision(10) << "sech(" << x << ") = " << fixed << setw(16) << 2 / plus << endl;
	cout << setprecision(10) << "csch(" << x << ") = " << fixed << setw(16) << 2 / minus << endl;


	system("pause");
}



Enter a value to be converted to multiple Hyperbolic Funtions before your eyes
.01

Converting: 0.01

sinh(0.01) =     0.0100001667
cosh(0.0100000000) =     1.0000500004
tanh(0.0100000000) =     0.0099996667
coth(0.0100000000) =   100.0033333111
sech(0.0100000000) =     0.9999500021
csch(0.0100000000) =    99.9983333527
Press any key to continue . . .

Last edited on
@JarJarz, please do not start a new thread on the same topic. It negates all the responses posted before. Please refer to the solution on your earlier thread at http://www.cplusplus.com/forum/general/222017/#msg1018824

The problem is that "fixed" is sticky; i.e. it (together with setprecision()) remains in place for the next numerical output. You will have to "unset" it before the first output on the next line. See your other thread. That solution will also show you how to avoid making an expensive and unnecessary four separate calls to pow() and also how to avoid code repetition in streamed output statements.

There are times when printf() has its appeals.
Last edited on
Topic archived. No new replies allowed.