Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having some syntax errors in my code, and not sure what is exactly wrong with it. Any suggestions as to how to clear up these errors?

The errors are as follows:
Error 1 The name 'InputMemberShipStatus' does not exist in the current context
Error 2 The name 'Parse' does not exist in the current context


Code is as follows:


C#
//DiscountApp.cs
//MAIN METHOD

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PA05
{
    class DiscountApp
    {
        static void Main(string[] args)
        {
            DisplayTitle();

            string status = InputMemberShipStatus();



            if (status == "Y" || status == "Yes" || status == "y" || status == "yes")
            {
                int age = InputAge();
                Discount discount = new Discount(age);
                double discountRate = discount.DetermineDiscount();
                Console.WriteLine("The discount is {0:p}", discountRate);
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("\n\tSorry, discounts apply to club members only.");
                Console.WriteLine();
            }
            Console.WriteLine();
            TerminateProgram();
        }

            //prompts for membership status
            public static string InputMembershipStatus()
            {
                Console.Write("Club Member? <y or="" n="">: ");
                string memberStatus = Console.ReadLine();
                Console.WriteLine();
                return memberStatus;
            }

                 //prompts for age of club member     
                public static int InputAge()
                {
                    Console.Write("Please enter the customer's age: ");
                    int age = Parse(Console.ReadLine());
                    Console.WriteLine();
                    return age;
                }

                static void DisplayTitle()
                {  //change colors and display title
                   Console.BackgroundColor = ConsoleColor.White;
                   Console.ForegroundColor = ConsoleColor.Black;
                   Console.Clear();
                   Console.Write("\n\t\tProgramming Assignment 5 - DetermineDiscount Discount");
                   Console.Write("\n\n\t\t\tPromgrammer: Nancy Hernandez");
                   Console.Write("\n\t\t_____________________________________________");
                   return;
                }

        public static void TerminateProgram()
        {   //terminates program by pressing Enter key
            Console.Write("\n\n\t_________________________________________________");
            Console.WriteLine("\n\tpress any key to end the program...");
            Console.ReadLine();
        }
    }
}</y>
Posted
Updated 6-Mar-12 17:09pm
v3

Alright it's just a minor change.

Change

C#
string status = InputMemberShipStatus();


to

C#
string status = InputMembershipStatus();


The problem was you did not look carefully at the code. Exact name of method should be specified.

The next one probably is:

C#
int age = Parse(Console.ReadLine());


to

C#
int age = Int32.Parse(Console.ReadLine());


I will assume that you are trying to just get integer values from user. You will not get any result by specifying Parse alone. The compiler will throw an error if you don't have a object named as "Parse".
 
Share this answer
 
Comments
LanFanNinja 6-Mar-12 23:17pm    
+5
In the InputAge() method, replace
C#
int age = Parse(Console.ReadLine());
as
C#
int age = int.TryParse(Console.ReadLine());


I don't see any errors in the "InputMemberShipStatus" method. It'll probably get cleared once the Parse syntax gets corrected.
 
Share this answer
 
Comments
Nithin Sundar 6-Mar-12 23:17pm    
The method name was "InputMembershipStatus". Instead a call to "InputMemberShipStatus" was made. That is the reason. The "s" in membership was specified as "S".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900