using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConTempConversion_Michelle
{
class Program
{
static void GetChoice(ref int ichoice)
{
Console.Write("Enter choice: ");
string input = Console.ReadLine();// get string from the user
bool result = int.TryParse(input, out ichoice);//convert input from string to ichoice int value
if (!result)
{
while (!result && ichoice > 3)
{
Console.WriteLine("Invalid value.Try again:");
input = Console.ReadLine();
result = int.TryParse(input, out ichoice);
}
}
}
static void Main(string[] args)
{
double fTemp;
double cTemp;
double convertToC;
double convertToF;
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
Console.WriteLine("1. Fahrenheit to Celsius");
Console.WriteLine("2. Celsius to Fahrenheit");
Console.WriteLine("3. Exit");
int ichoice = 0;
GetChoice(ref ichoice);
do
{
if (ichoice == 1)
{
Console.WriteLine("Enter Fahrenheit temperature: ");
fTemp = int.Parse(Console.ReadLine());
convertToC = ConvertCelcius(fTemp);
Console.WriteLine(fTemp + "Fahrenheit is " + convertToC + "Celsius");
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
GetChoice(ref ichoice);
}
if (ichoice == 2)
{
Console.WriteLine("Enter Celsius temperature: ");
cTemp = int.Parse(Console.ReadLine());
convertToF = ConvertCelcius(cTemp);
Console.WriteLine(cTemp + "Celsius is " + convertToF+ "Fahrenheit");
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("____________________________________________________");
GetChoice(ref ichoice);
}
if (ichoice == 3)
{
Console.WriteLine("Thank you for using the temperature conversion application. Please come again.");
}
else
{
Console.WriteLine("Invalid choice. Please choose again!");
}
}
while (ichoice < 3);
Console.ReadKey();
}
static double ConvertCelcius(double c)
{
double f;
return f = 9.0/5.0*c + 32;
}
static double ConvertFahrenheit(double f)
{
double c;
return c = (f - 32) * (5.0/9.0);
}
}
}
У меня только одна проблема с выходом этой программы. Преобразование из C в F является правильным, но от F до C является неправильным. Математическая формула правильная, но почему ее нет? пожалуйста, помогите ... Спасибо.C# Преобразование температуры (1 выпуск)
Мишель
Что ваш вход и выход? Что вы ожидаете в результате? Что ваша программа дает вам в результате? –
выход имеет три 3 варианта, 1 F скрытый до C, 2 C конвертировать в F, 3 программы выхода. если вы введете что-нибудь из этих трех вариантов, таких как 4, 5 или около того, тогда он предупредит пользователя о том, что это недопустимый ввод, и повторите попытку. – Michelle
Тот же ConvertCelcius вызывается в вариантах 1 и 2. Должна быть орфографическая ошибка. – Yuan