明天我正在檢查我的測試..我在程序中遇到了一個問題(我需要創建一個程序來顯示輸入數量的細目..我有與仙一個問題...)有關在C中崩潰的程序#
Console.Write("Enter amount: ");
double amt = double.Parse(Console.ReadLine());
thou = (int)amt/1000;
change = (int)amt % 1000;
fivehun = (int)change/500;
change = change % 500;
twohun = (int)change/200;
change = change % 200;
hun = (int)change/100;
change = change % 100;
fifty = (int)change/50;
change = change % 50;
twenty = change/20;
change = change % 20;
ten = (int)change/10;
change = change % 10;
five = (int)change/5;
change = change % 5;
one = (int)change/1;
change = change % 1;
twencents = (int)(change/.25);
change = change % .25; //there was an error here.. starting here
tencents = (int)(change/.10);
change = change % .10;
fivecents = (int)(change/.05);
change = change % .05;
onecent = (int)(change/.01);
change = change % .01;
Console.WriteLine("The breakdown is as follows: ");
Console.WriteLine("Php 1000 ={0} ", thou);
Console.WriteLine("Php 500 ={0} ", fivehun);
Console.WriteLine("Php 200 ={0} ", twohun);
Console.WriteLine("Php 100 ={0} ", hun);
Console.WriteLine("Php 50 ={0} ", fifty);
Console.WriteLine("Php 20 ={0} ", twenty);
Console.WriteLine("Php 10 ={0} ", ten);
Console.WriteLine("Php 05 ={0} ", five);
Console.WriteLine("Php 01 ={0} ", one);
Console.WriteLine("Php 0.25 ={0} ", twencents);
Console.WriteLine("Php 0.10 ={0} ", tencents);
Console.WriteLine("Php 0.05 ={0} ", fivecents);
Console.WriteLine("Php 0.01 ={0} ", onecent);
Console.ReadKey();
錯誤說我不能轉換雙爲int,所以我試着將它轉換我的鑄造它
change = (double) change % .25;
仍然是一個錯誤..
您是否嘗試將'.25'改爲'.25f'? –
是仍然不能正常工作.. – Franchette
看起來模數表達式的兩邊必須是'相同類型'。或者你需要自己重載它。請參閱:https://msdn.microsoft.com/en-US/library/0w4e0fzs(v=VS.100).aspx –