我尝试制作一些东西及其作品,但是当我试图在1个月内制作一个日期时它崩溃了。有人能帮我吗?代码是这样的:
int page = int.Parse(Console.ReadLine());
int campingDays = int.Parse(Console.ReadLine());
int pagesPerDay = int.Parse(Console.ReadLine());
int months = page / ((30 - campingDays) * pagesPerDay);
int years = months / 12;
int remainingMonths = months % 12;
Console.WriteLine("{0} years {1} months", years, remainingMonths);
答案 0 :(得分:1)
这就是我解决“0年1个月”问题的方法。你去吧!
int readedPages = (30 - campingDays) * regularDays;
if ((campingDays == 30) || (regularDays == 0))
{
Console.WriteLine("never");
}
else
{
double readDuration = Math.Ceiling(bookPages / (double)readedPages);
double years = (int)(readDuration / 12);
double remainingMonths =(readDuration % 12);
Console.WriteLine("{0} years {1} months", years, remainingMonths);
}
答案 1 :(得分:0)
每当
时,你会得到零除错误campingDays
,(30 - campingDays)
为30
pagesPerDay
是 - 0 有问题的一行:
int months = page / ((30 - campingDays) * pagesPerDay);
您可能需要2个if
语句来处理这些情况。
答案 2 :(得分:0)
Michal Ciechan是对的。 (请仔细阅读你的答案)
建议:
$(this).Ajax_Data("Employee", "Delete", { Id: CurrantID },
function () {
// onsuccess remove tr
$('tr:eq(' + RowIndex + ')').remove();
},
function () {
// onerror show message
alert('there is some thing wrong !!');
});