사용자가 클럽 회원인지 아닌지를 결정한 다음 나이를 기준으로 할인 금액을 표시하는 프로그램을 만들려고합니다. 필자는 프로그램을 작성했지만 해결책을 찾을 수없는 몇 가지 오류를 제공하고 있습니다. 나는이 사이트와 다른 사람들이 내가 뭘 잘못하고 있는지 발견하려고 노력했지만 모든 문제를 해결하지 못했습니다. 나는 배우는 프로그래머이기 때문에 정말 실종되었다는 것을 확신합니다. 문제에 대한 모든 의견은 크게 감사하겠습니다. 왜 현재 컨텍스트에 존재하지 않는 나이에 대한 오류가 발생하는지 알고 있습니다. '나이'가 올바르게 처리되도록 코드에서 누락 된 내용을 이해하지 못합니다.이름 '나이'가 현재 컨텍스트에 없습니다.
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();
}
}
}
'Main' 메소드는 아무 곳에도 정의되지 않았더라도'age' 변수를 사용합니다.'age' 매개 변수의 실제 값을 전달해야합니다. –
그 정도는 이해하지만, 메인 메소드에서 변수를 선언하더라도 두 메소드 'InputMembershipStatus()'및 'DertermineDiscount()'와 관련된 오류가 발생합니다. 정말 알아야 할 것은 어떻게 생각합니까? '연령'변수를 올바르게 처리하려면 처리해야합니다. –