Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting a "the name does not exist in the current context" error on this C# program?
    primarykey
    data
    text
    <p>Why am I getting a "<em>the name does not exist in the current context</em>" error on this C# program?</p> <p>Here is my class file:</p> <pre><code>namespace Exercise8 { class Park { Park aPark = new Park(); private string name; public string Name { get { name = Console.ReadLine(); return name; } set { } } private string location; public string Location { get { location = Console.ReadLine(); return location; } set { } } private string facilityType; public string FacilityType { get { facilityType = Console.ReadLine(); return facilityType; } set { } } private string facilitiesAvailable; public string FacilitiesAvailable { get { facilitiesAvailable = Console.ReadLine(); return facilitiesAvailable; } set { } } private double fee; public string sFee; public double Fee { get { fee = double.Parse(sFee); sFee = Console.ReadLine(); return fee; } set { } } private int noOfEmployees; public string sNoOfEmployees; public int NoOfEmployees { get { noOfEmployees = int.Parse(sNoOfEmployees); sNoOfEmployees = Console.ReadLine(); return noOfEmployees; } set { } } //variables for Cost Per Visitor. //noVisitors will be used in Calculate Revenue public double costPerVisitor; public double annualBudget = 200000; public double noVisitors = 10000; public double CalculateCostPerVisitor(double annualBudget, double noOfVisitors) { //divide annual budget by number of visitors return costPerVisitor = annualBudget / noVisitors; } //Calculate Revenue public double revenue; public double CalculateRevenue(double noOfVisitors,double fee) { //No of Visitors times Fee revenue = noVisitors * fee; return revenue; } public override string ToString() { return "Name of park: " + this.Name + "\nLocation: " + this.Location + "\nFacility Type: " + this.FacilityType + "\nFacility Fee: " + this.Fee + "\nNumber of employees: " + this.NoOfEmployees + "\nNumber of visitors recorded in the past 12 months: " + this.noVisitors + "Annual Budget: " + this.annualBudget; } } } </code></pre> <p>Here is my program:</p> <pre><code>namespace Exercise8 { class Program { public static void main (String [] args) { //Instantiate Objects Park aPark = new Park(); //Call Methods Console.WriteLine("Name of park: " + aPark.Name + "; Location of park: " + aPark.Location + "; Type of park: " + aPark.FacilityType); Console.WriteLine("Name of park: " + aPark.Name + "; Location of park: " + aPark.Location + "; Facilities available: " + aPark.FacilitiesAvailable); Console.WriteLine("Annual cost per visitor: " + CalculateCostPerVisitor()); Console.WriteLine("Revenue: " + CalculateRevenue()); //Below should hopefully return To String Console.WriteLine(aPark.ToString()); } } } </code></pre> <p>And these are the errors I'm seeing:</p> <blockquote> <p>The name 'CalculateCostPerVisitor' does not exist in the current context</p> <p>The name 'CalculateRevenue' does not exist in the current context line</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload