Sign in to follow this  

program problems

This topic is 3740 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

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

This topic is 3740 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this