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();
        }
    }
}

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.