我的方法CalculateFee给了我一个错误。这只是名为“CalculateFee”的红线
我已经尝试过将公共更改为私有并且没有帮助,即使对我来说有点愚蠢,即使是虚空也是如此...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FineForOverdueBooks
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("How many books were checked out?");
int booksCheckedOut = Convert.ToInt32(Console.ReadLine());
{
if (booksCheckedOut == 1)
{
Console.WriteLine("How many days is it overdue?");
}
else
Console.WriteLine("How many days are they overdue?");
}
int daysOverdue = Convert.ToInt32(Console.ReadLine());
int output = CalculateFee(booksCheckedOut, daysOverdue);
Console.WriteLine("Your late fee is: ", output.ToString("C"));
}
public static int **CalculateFee**(int booksCheckedOut, int daysOverdue)
{
double libraryFine = .10;
double additionalFine = .20;
if (daysOverdue <= 7)
{
for (double x = 0; x <= 7; x++)
{
libraryFine += .10;
}
return Convert.ToInt32(libraryFine);
}
if (daysOverdue > 7)
{
for (int x =0; x<=daysOverdue; x++)
{
additionalFine += .20;
}
return Convert.ToInt32(additionalFine);
}
}
}
}
我只是希望我的方法能够执行所以我可以看到我是否正确地执行了我的for循环以及是否需要更改一些东西(我可能会这样做)
对不起,如果这看似重复,我找不到任何与我的问题直接相关的内容。
因为CalculateFee
在所有情况下都不会返回。实际上在这种情况下,它只是不静态分析所有值,知道它永远不会到达那里。考虑使用else
public static int CalculateFee(int booksCheckedOut, int daysOverdue)
{
double libraryFine = .10;
double additionalFine = .20;
if (daysOverdue <= 7)
{
for (double x = 0; x <= 7; x++)
{
libraryFine += .10;
}
return Convert.ToInt32(libraryFine);
}
else
{
for (int x =0; x<=daysOverdue; x++)
{
additionalFine += .20;
}
return Convert.ToInt32(additionalFine);
}
}