我写一个程序,允许用户输入一个比萨饼的直径和程序计算的比萨将有多少片给你。这是我的代码到目前为止。控制台应用程序比萨
//DECLARATION OF VARIABLES
string Diameter = null; //The diameter of the pizza which the user will enter
int Slices; //The number of slices the user will get
const double SliceSize = 14.125; //The area of each slice of pizza
double Radius; //The radius of the pizza
double Area; //The area of the pizza
//INPUT
Console.WriteLine("Enter diameter of pizza:");
Diameter = Console.ReadLine();
double Diameter1 = Convert.ToDouble(Diameter);
//PROCESS
Radius = Diameter1/2;
Area = Math.PI*Math.Pow(Radius,2);
Slices = (int)(Area/SliceSize);
//OUTPUT
Console.WriteLine("A Diameter\" pizza will yeild {0:n0} slices", Slices);
// END - pause the program so the user can read the output and waits for user to press any key to exit the console
Console.WriteLine("\n\nPress any key to exit...");
Console.ReadKey();
我该如何四舍五入输出以及如何在输出writeline中引用比萨直径的直径?
什么是程序怎么了?它是否编译,运行? – MarkJ
什么是错的?而且,切片的量不依赖于比萨饼的直径。 – TJHeuvel
不,它不会编译。 msg错误表示“不能隐式地将类型'double'转换为'int'。存在明确的转换(你是否缺少一个转换?) –