我正在尝试制作一个程序来确定用户是否是俱乐部会员,然后根据他们的年龄显示他们的折扣金额。我已经编写了程序,但它给了我一些我无法找到解决方案的错误。我曾尝试搜索此站点和其他站点以查找我做错了什么,但我所做的每一个故障排除都失败了。我是一名学习型程序员,所以我确信这是我所缺少的东西。任何有关该问题的意见将不胜感激。我知道为什么我会收到有关当前上下文中不存在的年龄的错误,我只是不明白我的代码中缺少什么,以便正确处理“年龄”。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PA05
{
class DiscountApp
{
public static void Main(string[] args)
{
DisplayTitle();
InputMembershipStatus(age);
DetermineDiscount(age);
TerminateProgram();
}
public static void DisplayTitle()
{
Console.WriteLine("Programming Assignment 5 - Determine Discount\n\tProgrammer: ");
Console.WriteLine();
DrawLine();
}
public static void InputMembershipStatus(int age)
{
Console.WriteLine("Are you a Club Member? <Y or N>: ");
string aValue = Console.ReadLine();
if (aValue == "Y" || aValue == "y" || aValue == "Yes" || aValue == "yes")
{
age = InputAge();
}
else if (aValue == "N" || aValue == "n" || aValue == "No" || aValue == "no")
{
Console.WriteLine("Sorry, discounts apply to Club Members only.");
TerminateProgram();
}
}
public static int InputAge()
{
int age;
Console.Write("Please enter the customer's age: ");
age = Convert.ToInt32(Console.ReadLine());
return age;
}
public static double DetermineDiscount(int age)
{
double discountAmount;
if (age <= 10 || age >= 60)
{
discountAmount = .15;
Console.WriteLine("The discount is a {0:P2}", discountAmount);
}
else
{
discountAmount = .1;
Console.WriteLine("The discount is b {0:P2}", discountAmount);
}
return discountAmount;
}
public static void DrawLine()
{
Console.WriteLine("_________________________________________________________");
}
public static void TerminateProgram()
{
DrawLine();
Console.WriteLine("Press any key to terminate the program...");
Console.ReadKey();
}
}
}