Scientific notation to decimal?

Im recently new to prgramming and just wrote code that is a program for a relativity calculator. However many of my outputs (because the values tend to be large) end up in scientific notation. Although useful, its not great for the laymen, or nice looking.

How can I change it so that output is not in scientific notation?
here is the code:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130`` ``````// This program/converter is designed to find the desired 'real' values using Einstein's theory of relativity #include #include #include using namespace std; int main() { int choice; // User's choice float c; //Speed of light c = 299792458; cout << " " << endl; cout << "Welcome to Craig McRae's Relitivity Calculator!" << endl; cout << "What would you like to calculate?" << endl; cout << "1) Relativistic Length, Mass and Time dilation" << endl; cout << "2) Relativistic Velocity addition" << endl; cout << "3) Mass energy equivilence" << endl; cin >> choice; cout << " " << endl; if ( choice == 1 ) { float V; //Speed float length, mass, time; //Initial mass, length, and time float Rlength, Rmass, Rtime; //Relitivistic Length, mass and time float y; //Gamma or Lorentz transform cout << "How fast are you going? (m/s)"; cin >> V; while ( V >= c ) {cout << "IMPOSSIBLE! NOTHING CAN GO THAT FAST!" << endl; cout << "How fast are you REALLY going? (m/s)"; cin >> V; } cout << "How long were you traveling at this speed? (in seconds) "; cin >> time; cout << "Enter your mass in kg: "; cin >> mass; cout << "Enter your length in meters: "; cin >> length; y = sqrt(1 - ((V*V)/(c*c))); Rmass = mass / y; Rtime = time / y; Rlength = length * y; cout << " " << endl; cout << "Traveling at a speed of " << V << "m/s, to an observer at rest you would appear to have a length of " << Rlength << " meters, a mass of " << Rmass << " kg, and " << time << " seconds for you would be " << Rtime << " seconds for the observer!" << endl; } if ( choice == 2 ) { float V1, V2, Vf; //Velocities char ans; //For y/n cout << "What is the first velocity (in m/s)? "; cin >> V1; while ( V1 >= c ) {cout << "Error: Velocity can not be greater the speed of light" << endl; cout << "What is the first velocity (in m/s)? "; cin >> V1; } cout << "What is the second Velocity (in m/s)? "; cin >> V2; while ( V2 >= c ) {cout << "Error: Velocity can not be greater the speed of light" << endl; cout << "What is the second Velocity (in m/s)? "; cin >> V2; } cout << "Are they going in the same direction? (Y/N)"; cin >> ans; if ( ans == 'Y' || ans == 'y') {V2 = -1 * V2; } //Calculations Vf = abs(V1 + V2); if ( ans == 'Y' || ans == 'y') {V2 = -1 * V2; } Vf = Vf/(1 + (V1*V2)/(c*c)); cout << " " << endl; cout << "The combined relativistic speed of " << V1 << " and " << V2 << " is " << Vf << "m/s" << endl; }//End Choice =2 if (choice == 3) { int conv; //Which Converter to use float mass; float energy; float V; //Speed float P; //Momentum float y; //Gamma cout << "Which conversion are you doing?" << endl; cout << "1) Mass & momentum to Energy, or 2) Energy to mass " << endl; cin >> conv; if ( conv == 1 ) {cout << "What is the objects mass in kg? " << endl; cin >> mass; cout << "What is the objects speed in m/s? " << endl; cin >> V; while ( V >= c ) {cout << "Error: Speed can not surpass the speed of light" << endl; cout << "What is the objects Velocity?" << endl; cin >> V; } y = sqrt(1 - ((V*V)/(c*c))); P = (mass * V)/y; energy = sqrt((mass*c*c)*(mass*c*c) + (P*c)*(P*c)); cout << "The total energy stored in a " << mass << " kg object with a speed of " << V << " m/s is " << energy << " joules!" << endl; } if ( conv == 2) {cout << "Enter the energy you want to convert to mass, in joules: " << endl; cin >> energy; mass = energy/(c*c); cout << energy << " joules of energy is equivalent to " << mass << "kg. " << endl; } }//Choice = 3 return 0; }``````

Thanks!
`fixed` might help get the output formatted as you want. You can also use `setprecision()` (in <iomanip>) to set how many numbers to the right of the decimal point to output.

There's an example in the reference page here.
http://www.cplusplus.com/reference/ios/fixed/
Topic archived. No new replies allowed.