CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Junior Member
Join Date
Sep 2011
Posts
3

Hello guys! I am new to these forums and to programming in general. I have a program I am having some trouble with and was wondering if maybe any of you guys could help me. It runs fine until it gets to where it is suppose to use the math equation. Here is what I have so far.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int choice, input;
float temp, fahren, celsius;

printf ("\n\t\tRelationship between Fahrenheit and Celsius");
printf ("\n\n\t\t\t\t1) F - > C");
printf ("\n\t\t\t\t2) C - > F");
printf ("\n\n\t\t\tChoice (1/2) ?");
scanf ("%i", &choice);

if (choice == 1)
{ printf ("\n\n\t\t\tInput F:");
scanf ("%f", &temp);
fahren = (9.0 / 5.0) * (temp + 32.0);
printf ("\n\n\t\t\t%.2fF = %4.2fC");

}
else if (choice == 2)
{ printf ("\n\n\t\t\tInput C:");
scanf ("%f", &temp);
celsius = (5.0 / 9.0) * (temp - 32.0);
printf ("\n\n\t\t\t%.2fC = %4.2fF");

}
else if (choice > 2)
{ printf ("\n\n\t\t\tEnter 1 or 2 please.");
}

system("pause");

return 0;
}

This is what it is suppose to look like.

Relationship between Fahrenheit and Celsius

1 ) F - > C
2 ) C - > F

Choice (1/2)?

Input F:100

100.00F = 37.78C

Do more (Y/N)?

2. Member
Join Date
Aug 2009
Posts
440

Do you have to do this with C or can you use C++?

In each case, you calculate the value, but you never actually output the calculated value (or the value given to you by the user). In addition, you will need a while loop to get the "Do More (Y/N)? behavior you are looking for. Also, it looks like you mixed up your cases. Might cause a little confusion. Lastly, your equations are off slightly.
Last edited by Alterah; September 18th, 2011 at 01:35 AM.

3. Junior Member
Join Date
Sep 2011
Posts
3

Ah, I figured it out. Thank you.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•