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

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




Temprature converter C# console

 
Reply to this topicStart new topic

Temprature converter C# console

Tippan
6 Apr, 2008 - 05:06 PM
Post #1

New D.I.C Head
*

Joined: 6 Apr, 2008
Posts: 1

Hi everyone,

I am trying to get a c# console app to convert tempratures for me.

This is my very very first app.
I started reading C# for dummies tonight and felt inspired after completing the first tutorial successfully.

I maybe trying to run before i can walk, but anyway here's my code so far.

CODE
using System;

namespace ConsoleAppTemplate
{ // these are curly braces
// class Program is the “object” containing our code
public class Program
{
// This is where our program starts
// Every program has a Main() method somewhere
    static void Main(string[] args)
{
// here’s our code to make it do something
// prompt user to enter a name
    Console.WriteLine("Enter the temprature in farhenheit, please:");
    
// now read the name entered
        
    int nFarh = int.Parse(Console.ReadLine());

    int nCels;
    
    nCels = (nFarh - 32) * (5.0 / 9.0);
    

// Now Show the user the Celsius conversion
Console.WriteLine("The Temprature is Celsius =, " + nCels);
// wait for user to acknowledge the results
Console.WriteLine("Press Enter to terminate...");
Console.Read();
//code in Main() ends here
} // Main() ends here
} // class Program ends here
} // namespace ConsoleAppTemplate ends here


User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Temprature Converter C# Console
6 Apr, 2008 - 08:08 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Good work. All you need to do is define the variable nCels to be of type "double" because your equation uses doubles and the result is going to be a double (double meaning has a decimal point).

So instead of int nCels; just make it double nCels; and you are good to go.

smile.gif
User is offlineProfile CardPM
+Quote Post

nbarten
RE: Temprature Converter C# Console
10 Apr, 2008 - 04:13 AM
Post #3

D.I.C Head
**

Joined: 30 Apr, 2007
Posts: 112



Thanked: 2 times
My Contributions
QUOTE(Martyr2 @ 6 Apr, 2008 - 09:08 PM) *

Good work. All you need to do is define the variable nCels to be of type "double" because your equation uses doubles and the result is going to be a double (double meaning has a decimal point).

So instead of int nCels; just make it double nCels; and you are good to go.

smile.gif


Also i never knew that the WriteLine() method accepts also an int as an argument?

I always do it like this: nCels.toString()

This post has been edited by nbarten: 10 Apr, 2008 - 05:25 AM
User is offlineProfile CardPM
+Quote Post

wiko
RE: Temprature Converter C# Console
15 Apr, 2008 - 12:26 PM
Post #4

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 21


My Contributions
no, it does accept int as an argument. Good job Tippan, thx martyr for your notice. I didn't notice it!! lol
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:53PM

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