我寫一個程序,允許用戶輸入一個比薩餅的直徑和程序計算的比薩將有多少片給你。這是我的代碼到目前爲止。控制檯應用程序比薩
//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'。存在明確的轉換(你是否缺少一個轉換?) –