0

Can anyone tell me whats wrong with this code?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int CelsiusTillFarenheit(double Celsius, double Farenheit, string Text)
        {
            Celsius = double.Parse(Text);
            Celsius / 5.0 * 9 + 32 = Farenheit;
            int Farenheit2;
            Farenheit2 = Convert.ToInt32(Farenheit);
            return Farenheit2;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Skriv in grad i Celsius");
            string Text;
            Text = Console.ReadLine();
            Console.WriteLine ("Det blir " + CelsiusTillFarenheit(Text) + " Farenheit");
            Console.ReadLine();
        }
    }
}
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by ddanbe
0

First, you declared a function called CelsiusTillFarenheit that takes 3 arguments. And in the Main function you call that function with only 1 argument.

Then the calculations are wrong. This is the correct way:

static int CelsiusTillFarenheit(string Text)
        {
            double Celsius, Farenheit;
            Celsius = double.Parse(Text);
            Farenheit =Math.Round(Celsius / 5.0 * 9 + 32, 0);
            int Farenheit2;
            Farenheit2 = Convert.ToInt32(Farenheit);
            return Farenheit2;
        }

I used the Math.Round(); function to remove the decimals from the operation.

Edited by charlybones: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.