在83年零4个月内转换1000个月

时间:2015-04-26 11:21:11

标签: c# datetime

我尝试制作一些东西及其作品,但是当我试图在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);

3 个答案:

答案 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 !!');
                });
相关问题