我的代码工作得很好,直到我到达程序,我的输出现在落在可接受的范围内。
我是这样添加的:
using System;
namespace ITSS131
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("hello what is your car loan amount.");
decimal loan = decimal.Parse(Console.ReadLine());
Console.WriteLine("What is your APR");
decimal APR = decimal.Parse(Console.ReadLine());
Console.WriteLine("What is the monthly payment");
int monthlypayment = int.Parse(Console.ReadLine());
int currentmonth = 0;
int u = 0;
int c = 1;
while (loan >= 0.00m)
{
decimal.Round(APR);
decimal TAX = APR / 12.00m / 100.00m;
decimal.Round(TAX);
decimal TAX2 = TAX * loan;
decimal Tax3 = monthlypayment - TAX2;
decimal.Round(loan = loan + TAX2 - monthlypayment);
currentmonth++;
Console.WriteLine($"Month - Interst - Principle - Balance");
Console.WriteLine($"{currentmonth} {TAX2.ToString("C")} {Tax3.ToString("C")} {loan.ToString("C")}");
}
}
}
}输出应该是
1 $78.75 $271.25 $20,728.75
2 $77.73 $272.27 $20,456.48
3 $76.71 $273.29 $20,183.19
4 $75.69 $274.31 $19,908.88
5 $74.66 $275.34 $19,633.54
6 $73.63 $276.37 $19,357.17
7 $72.59 $277.41 $19,079.76
8 $71.55 $278.45 $18,801.31
9 $70.50 $279.50 $18,521.81
10 $69.46 $280.54 $18,241.27
11 $68.40 $281.60 $17,959.67
12 $67.35 $282.65 $17,677.02
13 $66.29 $283.71 $17,393.31
14 $65.22 $284.78 $17,108.53
15 $64.16 $285.84 $16,822.69
16 $63.09 $286.91 $16,535.78
17 $62.01 $287.99 $16,247.79
18 $60.93 $289.07 $15,958.72
19 $59.85 $290.15 $15,668.57
20 $58.76 $291.24 $15,377.33
21 $57.66 $292.34 $15,084.99
22 $56.57 $293.43 $14,791.56
23 $55.47 $294.53 $14,497.03
24 $54.36 $295.64 $14,201.39
25 $53.26 $296.74 $13,904.65
26 $52.14 $297.86 $13,606.79
27 $51.03 $298.97 $13,307.82
28 $49.90 $300.10 $13,007.72
29 $48.78 $301.22 $12,706.50
30 $47.65 $302.35 $12,404.15
31 $46.52 $303.48 $12,100.67
32 $45.38 $304.62 $11,796.05
33 $44.24 $305.76 $11,490.29
34 $43.09 $306.91 $11,183.38
35 $41.94 $308.06 $10,875.32
36 $40.78 $309.22 $10,566.10
37 $39.62 $310.38 $10,255.72
38 $38.46 $311.54 $9,944.18
39 $37.29 $312.71 $9,631.47
40 $36.12 $313.88 $9,317.59
41 $34.94 $315.06 $9,002.53
42 $33.76 $316.24 $8,686.29
43 $32.57 $317.43 $8,368.86
44 $31.38 $318.62 $8,050.24
45 $30.19 $319.81 $7,730.43
46 $28.99 $321.01 $7,409.42
47 $27.79 $322.21 $7,087.21
48 $26.58 $323.42 $6,763.79
49 $25.36 $324.64 $6,439.15
50 $24.15 $325.85 $6,113.30
51 $22.92 $327.08 $5,786.22
52 $21.70 $328.30 $5,457.92
53 $20.47 $329.53 $5,128.39
54 $19.23 $330.77 $4,797.62
55 $17.99 $332.01 $4,465.61
56 $16.75 $333.25 $4,132.36
57 $15.50 $334.50 $3,797.86
58 $14.24 $335.76 $3,462.10
59 $12.98 $337.02 $3,125.08
60 $11.72 $338.28 $2,786.80
61 $10.45 $339.55 $2,447.25
62 $9.18 $340.82 $2,106.43
63 $7.90 $342.10 $1,764.33
64 $6.62 $343.38 $1,420.95
65 $5.33 $344.67 $1,076.28
66 $4.04 $345.96 $730.32
67 $2.74 $347.26 $383.06
68 $1.44 $348.56 $34.50
68 $0.13 $34.50 $0.00但我却得到了
Month - Interst - Principle - Balance
1 $78.75 $271.25 $20,728.75
Month - Interst - Principle - Balance
2 $77.73 $272.27 $20,456.48
Month - Interst - Principle - Balance
3 $76.71 $273.29 $20,183.19
Month - Interst - Principle - Balance
4 $75.69 $274.31 $19,908.88
Month - Interst - Principle - Balance
5 $74.66 $275.34 $19,633.54
Month - Interst - Principle - Balance
6 $73.63 $276.37 $19,357.17
Month - Interst - Principle - Balance
7 $72.59 $277.41 $19,079.76
Month - Interst - Principle - Balance
8 $71.55 $278.45 $18,801.30
Month - Interst - Principle - Balance
9 $70.50 $279.50 $18,521.81
Month - Interst - Principle - Balance
10 $69.46 $280.54 $18,241.27
Month - Interst - Principle - Balance
11 $68.40 $281.60 $17,959.67
Month - Interst - Principle - Balance
12 $67.35 $282.65 $17,677.02
Month - Interst - Principle - Balance
13 $66.29 $283.71 $17,393.31
Month - Interst - Principle - Balance
14 $65.22 $284.78 $17,108.53
Month - Interst - Principle - Balance
15 $64.16 $285.84 $16,822.69
Month - Interst - Principle - Balance
16 $63.09 $286.91 $16,535.78
Month - Interst - Principle - Balance
17 $62.01 $287.99 $16,247.78
Month - Interst - Principle - Balance
18 $60.93 $289.07 $15,958.71
Month - Interst - Principle - Balance
19 $59.85 $290.15 $15,668.56
Month - Interst - Principle - Balance
20 $58.76 $291.24 $15,377.32
Month - Interst - Principle - Balance
21 $57.66 $292.34 $15,084.98
Month - Interst - Principle - Balance
22 $56.57 $293.43 $14,791.55
Month - Interst - Principle - Balance
23 $55.47 $294.53 $14,497.02
Month - Interst - Principle - Balance
24 $54.36 $295.64 $14,201.38
Month - Interst - Principle - Balance
25 $53.26 $296.74 $13,904.64
Month - Interst - Principle - Balance
26 $52.14 $297.86 $13,606.78
Month - Interst - Principle - Balance
27 $51.03 $298.97 $13,307.80
Month - Interst - Principle - Balance
28 $49.90 $300.10 $13,007.71
Month - Interst - Principle - Balance
29 $48.78 $301.22 $12,706.49
Month - Interst - Principle - Balance
30 $47.65 $302.35 $12,404.14
Month - Interst - Principle - Balance
31 $46.52 $303.48 $12,100.65
Month - Interst - Principle - Balance
32 $45.38 $304.62 $11,796.03
Month - Interst - Principle - Balance
33 $44.24 $305.76 $11,490.27
Month - Interst - Principle - Balance
34 $43.09 $306.91 $11,183.35
Month - Interst - Principle - Balance
35 $41.94 $308.06 $10,875.29
Month - Interst - Principle - Balance
36 $40.78 $309.22 $10,566.07
Month - Interst - Principle - Balance
37 $39.62 $310.38 $10,255.70
Month - Interst - Principle - Balance
38 $38.46 $311.54 $9,944.16
Month - Interst - Principle - Balance
39 $37.29 $312.71 $9,631.45
Month - Interst - Principle - Balance
40 $36.12 $313.88 $9,317.56
Month - Interst - Principle - Balance
41 $34.94 $315.06 $9,002.50
Month - Interst - Principle - Balance
42 $33.76 $316.24 $8,686.26
Month - Interst - Principle - Balance
43 $32.57 $317.43 $8,368.84
Month - Interst - Principle - Balance
44 $31.38 $318.62 $8,050.22
Month - Interst - Principle - Balance
45 $30.19 $319.81 $7,730.41
Month - Interst - Principle - Balance
46 $28.99 $321.01 $7,409.40
Month - Interst - Principle - Balance
47 $27.79 $322.21 $7,087.18
Month - Interst - Principle - Balance
48 $26.58 $323.42 $6,763.76
Month - Interst - Principle - Balance
49 $25.36 $324.64 $6,439.12
Month - Interst - Principle - Balance
50 $24.15 $325.85 $6,113.27
Month - Interst - Principle - Balance
51 $22.92 $327.08 $5,786.20
Month - Interst - Principle - Balance
52 $21.70 $328.30 $5,457.89
Month - Interst - Principle - Balance
53 $20.47 $329.53 $5,128.36
Month - Interst - Principle - Balance
54 $19.23 $330.77 $4,797.59
Month - Interst - Principle - Balance
55 $17.99 $332.01 $4,465.58
Month - Interst - Principle - Balance
56 $16.75 $333.25 $4,132.33
Month - Interst - Principle - Balance
57 $15.50 $334.50 $3,797.83
Month - Interst - Principle - Balance
58 $14.24 $335.76 $3,462.07
Month - Interst - Principle - Balance
59 $12.98 $337.02 $3,125.05
Month - Interst - Principle - Balance
60 $11.72 $338.28 $2,786.77
Month - Interst - Principle - Balance
61 $10.45 $339.55 $2,447.22
Month - Interst - Principle - Balance
62 $9.18 $340.82 $2,106.40
Month - Interst - Principle - Balance
63 $7.90 $342.10 $1,764.30
Month - Interst - Principle - Balance
64 $6.62 $343.38 $1,420.91
Month - Interst - Principle - Balance
65 $5.33 $344.67 $1,076.24
Month - Interst - Principle - Balance
66 $4.04 $345.96 $730.28
Month - Interst - Principle - Balance
67 $2.74 $347.26 $383.01
Month - Interst - Principle - Balance
68 $1.44 $348.56 $34.45
Month - Interst - Principle - Balance
69 $0.13 $349.87 ($315.42)有人能帮我到0吗?
发布于 2020-11-13 05:18:08
将您的代码更改为:
Console.WriteLine($"Month - Interst - Principle - Balance");
while (loan > 0.10m)
{
decimal TAX = APR / 12.00m / 100.00m;
decimal TAX2 = decimal.Round(TAX * loan, 2);
decimal Tax3 = decimal.Round(monthlypayment - TAX2, 2);
if (loan > monthlypayment-TAX2) loan = loan + TAX2 - monthlypayment;
else
{
Tax3 = loan + TAX2;
loan = 0m;
}
currentmonth++;
Console.WriteLine($"{currentmonth} {TAX2.ToString("C")} {Tax3.ToString("C")} {loan.ToString("C")}");
}发布于 2020-11-13 06:08:38
请注意,您的最后一次付款不是全额付款-使用任意的APR和付款金额,您不会总是获得完整的、甚至是摊销的时间表。如果你想在结尾处显示较小的付款,只需更改
decimal Tax3 = monthlypayment - TAX2;
loan = loan + TAX2 - monthlypayment;
decimal.Round(loan,2);至
decimal Tax3 = Math.Max(monthlypayment - TAX2, loan) ;
loan = loan - Tax3;
loan = decimal.Round(loan,2);这将解决三个问题:
舍入将本金限制在剩余本金余额formula
round的结果(舍入不改变原始值-它返回四舍五入的值)中的本金减少值
发布于 2020-11-13 06:26:55
尝尝这个
class Program
{
private static Ink InkOverlay { get; set; }
public static async Task Main(string[] args)
{
Console.WriteLine("hello what is your car loan amount.");
decimal loan = decimal.Parse(Console.ReadLine());
Console.WriteLine("What is your APR");
decimal APR = decimal.Parse(Console.ReadLine());
Console.WriteLine("What is the monthly payment");
decimal monthlypayment = decimal.Parse(Console.ReadLine());
int currentmonth = 0;
int u = 0;
int c = 1;
while (loan > 0.00m)
{
decimal.Round(APR);
decimal TAX = APR / 12.00m / 100.00m;
decimal.Round(TAX);
decimal TAX2 = TAX * loan;
if((loan + TAX2) < monthlypayment)
{
monthlypayment = loan + TAX2;
}
decimal Tax3 = monthlypayment - TAX2;
decimal.Round(loan = loan + TAX2 - monthlypayment);
currentmonth++;
Console.WriteLine($"Month - Interst - Principle - Balance");
Console.WriteLine($"{currentmonth} {TAX2.ToString("C")} {Tax3.ToString("C")} {loan.ToString("C")}");
}
}
}https://stackoverflow.com/questions/64811657
复制相似问题