Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,171 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,902 people online right now. Registration is fast and FREE... Join Now!




My program does not return the output to the screen

 
Reply to this topicStart new topic

My program does not return the output to the screen, Fahrenheit to Celsius conversion

C-Rookie
16 Dec, 2007 - 12:55 AM
Post #1

New D.I.C Head
*

Joined: 15 Dec, 2007
Posts: 8


My Contributions
/* Fahrenheit to Celsius conversion program */

/*Filename: week2-pkc.c */
/* This program prompts the user to enter a decimal Fahrenheit temperature to be converted to Celsius */
/*Ask the user to enter a faherinheit temperature to be converted to Celsius */
#include <stdio.h> /*Define data type*/
/*#include <ctype.h> Define data type*/
main()
{
float Fahrenheit; /*Variable to hold Fahrenheit*/
float Celsius; /*Variable to hold Celsius*/
printf("Please enter a Faherinheit temperature to be converted to Celsius\n example 82 or 71.5\n");
scanf(" %.2f",&Fahrenheit);
Celsius = (Fahrenheit - 32) * (5.0/9.0); /*Perform calculation to convert fahrenheit to Celsius*/
printf("Fahrenheit = &Fahrenheit\n, Celsius = &Celsius\n "); /*Print out Fahrenheit number given and the Celsius Equivilant*/
printf("Press Enter to exit");
return 0;
}
User is offlineProfile CardPM
+Quote Post

baavgai
RE: My Program Does Not Return The Output To The Screen
16 Dec, 2007 - 02:12 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
This should move to C.

Your scanf was wrong, the pattern meant you never got a value. The output problem was because printf expects a list of arguments to substitute for format placeholders. You put a variable reference in the string. While this style can work in some languages, the printf function in C doesn't do that.

Here's some corrected code:
CODE

/*Filename: week2-pkc.c */
/* This program prompts the user to enter a decimal Fahrenheit temperature to be converted to Celsius */
/*Ask the user to enter a faherinheit temperature to be converted to Celsius */
#include <stdio.h> /*Define data type*/
/*#include <ctype.h> Define data type*/
main() {
    float Fahrenheit; /*Variable to hold Fahrenheit*/
    float Celsius; /*Variable to hold Celsius*/
    printf("Please enter a Faherinheit temperature to be converted to Celsius\n example 82 or 71.5\n");
    scanf("%f",&Fahrenheit);
    Celsius = (Fahrenheit - 32) * (5.0/9.0); /*Perform calculation to convert fahrenheit to Celsius*/
    printf("Fahrenheit = %.2f\nCelsius = %.2f\n", Fahrenheit, Celsius); /*Print out Fahrenheit number given and the Celsius Equivilant*/
    printf("Press Enter to exit");
    return 0;
}


Hope this helps.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:33AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month