一开始,我想让用户在程序中输入“公式”这个词才能继续。如果输入任何其他内容,它将显示“名称错误。再试一次。” 它会要求用户再次输入名称。
最后,当程序询问用户是否要重试时,如果用户输入“是”,则程序将重新从头开始。如果用户输入“否”,那么它将退出程序。
这是代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication_program
{
class formula
{
internal double numberOne, numberTwo, numberThree;
internal double formulaResult()
{
return (6 * numberOne * numberTwo) + (6 * numberTwo * numberThree) + (6 * numberThree * numberOne);
}
internal double formulaResultTwo()
{
return formulaResult() * 0.9;
}
}
class Program
{
static void Main(string[] args)
{
formula integer = new formula();
string name;
Console.WriteLine("Enter name");
name = Console.ReadLine();
//Enter the word "Formula" to start calculating.
//If anything else is entered then it will say "Wrong name. Try again."
Console.WriteLine("Enter the first number");
integer.numberOne = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number");
integer.numberTwo = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the third number");
integer.numberThree = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The first result is {0}", integer.formulaResult());
Console.WriteLine("The second result is {0}", integer.formulaResultTwo());
Console.WriteLine("\nDo you want to try again?");
//Enter "Yes" to try again or enter "No" to exit.
Console.ReadLine();
}
}
}