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
//This program calculates the values of several hyperbolic functions
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace 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 . . .
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.