I wanted to go back to school to learn more the bad thing it is an online learning class. I have emailed the Instructor a few times and have not got any response. This is what I have done all alone. My biggest issues it that my final outcome is 8 or more numbers. I have gone through the book and it is not helping. I have to make a temperature converter with user options. for either C or F. Can anyone look and point me on the right path please.
int main()
{
int opt;
int input;
float c;
float f;
system("COLOR 1C");
printf("Welcome to the Temperature Converter Program\n\n");
printf("Please choose one of the following:\n");
printf("Press (1) for Farenheit to Celsius.\n");
printf("Press (2) for Celsius to Farenheit.\n");
scanf("%d", &opt);
printf("Please enter Temperature:\n");
scanf("%d", &input);
if (opt==1)
{
c=(input-32.)*5.0/9.0;
printf("Temperature is in Celsius %d\n", &c);
}
else if (opt==2)
{
f=(input+32.0)*9.0/5.0;
printf("Temperature is in Farenheit %d\n", &f);
}
When I do that an I press (1) for Farenheit to Celsius and enter a degree of 100 my Celsius temp is -1.#QNAN0. So is my function correct or did I do something else wrong.
By looking at yours i think I enter my equations correct. The issue I have if is that my answer is only has one decimal and a bunch of letters. I have worked on this for 3 days and this is how far I have gotten. I have did nothing but read my book and watch youtube videos.
One misplaced character will give you unexpected results.
2. Your equations are not correct. Close, but a little off. Double check them. Add parenthesis, sometimes we assume a certain order of operations and we are wrong.
I'd fix the printf() problem first, then you can more easily check your equations. Just set "c" to a fixed value and see what it prints out. Once that's working then deal with the equations.
I would like to thank everyone who has shared there knowledge with me. But it appears I am getting more confused than ever. I did change my printf to ( "%f"). Also I will relook at my equation. But one thing should I remove my int input?
Are you !%$@$ me it was the stupid (&) in my printf that was missing me up. OMG I need to kick myself really hard in "you know what" I have been reading the links that you and others have provided me I am rereading my book. I feel really stupid that something so simple drove me to the point I want to quit. I thank you mpacker and I would like to say sorry. I would like it more if you teach me.
P.S
You are right my equation is wrong I will look into it.
Are you !%$@$ me it was the stupid (&) in my printf that was missing me up. OMG I need to kick myself really hard in "you know what"
This is why we encourage beginners to use the iostream instead of the C library. It is type safe.
As for the equations. It looks like your conversion from F to C is correct, but C to F is not. To fix it, just take the correct one: C = (F - 32.0) * 5.0 / 9.0;
and solve for F.