Jump to content
  • Advertisement
Sign in to follow this  
rlury

program problems

This topic is 3928 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i wrote a code for a simple program but when i run it im getting a numerical value for my outputs, i dont know why. i need to input a temp, and get have the program recognize it within 5% of 5 different subtances if the temp is not in the 5% it has to say unknown. i put in the temp and get numerical values though i dont know what im doin wrong. #include <iostream> #include <cmath> using namespace std; int main () { double water, mercury, copper, silver, gold, temp, unknown; cout << "Enter temp of substance : " ; cin >> temp; if (95 < temp && temp < 105) cout << water << endl; else if (339.15 < temp && temp < 374.85) cout << mercury << endl; else if (1127.65 < temp && temp < 1246.350) cout << copper << endl; else if (2053.35 < temp && temp < 2302.65) cout << silver << endl; else if (2527 < temp && temp < 2793) cout << gold << endl; else cout << unknown << endl; system ("pause"); return 0; } here is the code and i need to test for 1231 temp and have it say copper

Share this post


Link to post
Share on other sites
Advertisement

double water, mercury, copper, silver, gold, temp, unknown;

you are telling the computer that these are double-precision numbers.

then, you tell the computer to output them like so:

cout << water << endl;

enclosing water in double quotes "water", should fix your problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!