Can anyone provide help with this small C++ program.

Infidelity

Banned
Apr 16, 2001
615
0
0
I had only one class in C++ and because of the current situation in NYC all classes have been cancelled. However, I still need to do the homework. I wrote the program and it works fine, yet, I want to make it display the answer in more detial. What I mean is. Instead of 2.17e17 I want it to be 2.9864e17. Can anyone tell me what I'm doing wrong or need to edit in order for this to work the way I want it to.

double amount_of_mass;
float e_energy_produced;
const double c = 3.00 * ::pow(10.00,8.00);



cout<< "Enter a mass <in kilograms>:";
cin >> amount_of_mass;

e_energy_produced = amount_of_mass * c * c;


// cout.setf(ios::fixed);
// cout.setf(ios::showpoint);
// cout.precision(5);


cout << "\n";
cout << amount_of_mass << " " << "kilograms of matter will release"
<< " " << (e_energy_produced) << " " << "kilojules of energy."<< endl;


return 0;

}
 

Burnt

Platinum Member
Mar 20, 2001
2,211
0
0
I'm no expert but you could try changing the float variable to a double, which will allow you to store more numbers and be more accurate.
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
I think you need to set your iosflags. "setiosflags:: etc..."

plus, change all your variables to floats. Some compliers don't like having to cast types and you have less control over your output. The other way to do it is to force the program to cast the result as a double.

Hope this helps, but I could be wrong as I've been doin java for the past god knows how long.