954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Am I missing anything? ConvertTemp Program(usage of methods), what am I missing?

Ok so after modeling after another application Im modifying a previous console app which converts Celsius temp (with user input) to Fahrenheit. Visual Studio has annoying habits to give errors on variables that "haven't been declared yet". Im looking at this and wondering why the heck is it complaining. I have the identifier's all correct and took into account the syntax errors that could be done.
i think for the first line "const float" Im wondering whether to just place "Celsius * 9/5 +32 " instead of just "c" since it doesn't like that.

const float CELSIUS_TO_FAHRENHEIT =   * 9/5 + 32; 

            double celsius;

            DisplayInstructions();
            celsiusTemp = GetCelsiusTemp();
            celsius = CalculateCelsius(celsiusTemp, CELSIUS_TO_FAHRENHEIT);

        }
        public static void DisplayInstructions()
        {
            Console.WriteLine("Welcome to the Celsius to Fahrenheit Converter!");

        }

        public static double GetCelsiusTemp()
        {
            string inValue;
            int celsius;

            Console.WriteLine("\n\nPlease Enter the Celsius value you wish to convert");
            inValue = Console.ReadLine();
            celsius = int.Parse(inValue);
            return celsius;
        }

        public static int CalculateCelsius(int celsius, int CELSIUS_TO_FAHRENHEIT)
        {
            return celsius * (9/5 + 32);
        }

        public static void DisplayResults(int celsius)
        {
            Console.Clear();
            Console.WriteLine("Temperture in Fahrenheit");
            Console.WriteLine("------------------------");
            Console.Read();
        }


Thanks for the help

techlawsam
Junior Poster in Training
56 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

1) Remove the * typo before the numbers: const float CELSIUS_TO_FAHRENHEIT = *(9/5+32);
2) The function should be CalculateCelsius(double, double) not (int,int).

edit: Also you never declared celsiusTemp.

double celsius, celsiusTemp;

nkm123
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

What you are missing is in line 29, this part celsius * (9/5 + 32). Since all those values are integers, it's going to do integer math on them. What this means to you is that 9/5 = 1. The other problem with that line is that you put () in there, remove them otherwise it will multiply celsius by 33 each time (or 33.8 once you fix the int/double problem).

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

The problem is with the first line, a '*' would actually mean a pointer to the compiler. @nkm123 : placing * before the numbers would still not work. the reason being pointer understanding by compiler.
the reason i guess you are using * is to directly manipulate the multiplication on line 29, right..? if so, please remove it, you can use
return celsius * CELSIUS_TO_FAHRENHEIT; directly.

arunkumars
Junior Poster
186 posts since Jul 2009
Reputation Points: 26
Solved Threads: 22
 

You could also use this snippet: http://www.daniweb.com/software-development/csharp/code/217189
Here, pure by accident :sweat: I avoided the problem with integer calculations, Momerath is talking about

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

interesting I will look into that, I finished the project it took a lot of tinkering around and rearranging my method statements around and moving in and out of the method, class, etc. But again you guys gave me the help and direction needed in order to do that!

techlawsam
Junior Poster in Training
56 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: