15,746,302 members
1.00/5 (1 vote)
See more:
(C# Visual Studio 2019) Hello, my professor wants us to do the following code shown in the picture : https://i.stack.imgur.com/ONNSV.png

We are fairly new into the course and have have talked about only a few of conversion methods.

What I have tried:

Here is my attempt, but with an error that I cannot seem to wrap my head around. If someone can help me out or provide a solution, thanks!

C#
```Console.Write("Enter degrees Fahrenheit to convert to Celsius OR

\nenter degrees Celsius to convert to Fahrenheit.");

Console.Write("\n\nCurrent temperature scale (C for Celsius; F for Fahrenheit): ");

Console.Write("Current degrees: ");

double degreeCelsius = 5 / 9 * (tempscale - 32);

double degreeFahrenheit = 9 / 5 * (degreeCelsius + 32);

if (tempscale == degreeFahrenheit)

Console.Write(degreeFahrenheit + "degrees Fahrenheit is" + degreeCelsius + "degrees Celsius");

if (tempscale == degreeCelsius)

Console.Write(degreeCelsius + "degrees Celsius is" + degreeFahrenheit + "degrees Fahrenheit");

Console.Write("\n\nPress any key to continue...");

Posted
Updated 30-Oct-20 0:05am
v2

## Solution 1

Quote:
with an error that I cannot seem to wrap my head around
Put a breakpoint at the start of your code, and single step through it (F11): observe the values of variables to find unexpected results.

Describe the error, and where it occurs.

These simple methods are the foundation of debugging, and they are as essential for competence as a programmer as mastery of the computer language you use.

CodeProject has many articles on debugging: [^] ... to start with: I recommend [^] and [^]

v2
TheRealSteveJudge 30-Oct-20 6:19am
Debugging and a more detailed description of the symptoms is always a good idea! 5*

## Solution 2

As Bill suggested debugging is what every developer must learn in order to know what is happening inside when the programme does not behave as expected.
Please let me give you some more suggestions.

The first problem is
C#
```Console.Write("Enter degrees Fahrenheit to convert to Celsius OR

\nenter degrees Celsius to convert to Fahrenheit.");```

will sabotage a successful compilation.
You should replace it by
C#
`Console.Write("Enter degrees Fahrenheit to convert to Celsius OR\nenter degrees Celsius to convert to Fahrenheit.");`

The next problem is
C#
`double tempscale = Convert.ToDouble(Console.ReadLine());`

You are expecting the user to enter either 'C' or 'F'.
No matter what the user will enter you convert it to double which is not a suitable data type for characters.
You should replace it by
C#
`var tempscale = Console.ReadLine();`

The lines to follow then make no sense.
Hint:
C#
```if (tempscale == "C")
{
double degreeFahrenheit = 9 / 5 * (currentdeg + 32);
Console.Write(currentdeg + "degrees Celsius is " + degreeFahrenheit + " degrees Fahrenheit");```

Then you must do something similar for the opposite direction.
BTW: Your formula for conversion from Fahrenheit to Celsius is wrong!
Moreover you must take care of error handling to catch invalid inputs e.g. the user entering other letters than 'C' or 'F' in the first Console.Readline.
What will happen if the user enters any other than valid numbers in the second Console.ReadLine?

v2