1 Replies - 947 Views - Last Post: 01 March 2011 - 02:32 AM Rate Topic: -----

#1 cats_rule  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 21-November 10

An object reference is required error. SOLVED

Posted 01 March 2011 - 02:24 AM

im getting the error An object reference is required for the non-static field, method, or property 'Worksheet_4_Task_4" but i cant seem to work out why the error is there???
Can anyone help??
Many thanks

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

namespace Worksheet_4_Task_4
{
    class Program
    {
        static void Main(string[] args)
        {
            string num = "";
            int value = 0;
            
            while (value != 6)
            {
                DisplayMenu();
                num = Console.ReadLine();
                value = ConvertToNumber(num);
                DisplayMessage(value);

            }
            

        }
        //display a menu of options for user to choose from

        void DisplayMenu()
        {
            Console.WriteLine("1.Read and sum 5 numbers then display result");
            Console.WriteLine("2.Read and calculate the average of 5 numbers then display result");
            Console.WriteLine("3.Store 5 numbers and find the maximum & minimum values then display results");
            Console.WriteLine("4.Enter some text,enter number of times to print text,print text");
            Console.WriteLine("5.Enter two numbers then select an add,subtract or multiply operation and display result");
            Console.WriteLine("6.Quit");
        }

       //convert a string number to its numeric equivalent

        int ConvertToNumber(string numStr)
        {
            int val = 6;
            if (numStr == "one")
            {
                val = 1;
            }
            else if (numStr == "two")
            {
                val = 2;
            }
            else if (numStr == "three")
            {
                val = 3;
            }
            else if (numStr == "four")
            {
                val = 4;
            }
            else if (numStr == "five")
            {
                val = 5;
            }
            return val;
        }


        // display correct message

        void DisplayMessage(int val)
        {
            if (val == 1)
            {
                Console.WriteLine("I will Read and sum 5 numbers then display result");
            }
            if (val == 2)
            {
                Console.WriteLine("I will Read and calculate the average of 5 numbers then display result");
            }
            if (val == 3)
            {
                Console.WriteLine("I will Store 5 numbers and find the maximum & minimum values then display results");
            }
            if (val == 4)
            {
                Console.WriteLine("I will Enter some text,enter number of times to print text,print text");
            }
            if (val == 5)
            {
                Console.WriteLine("I will Enter two numbers then select an add,subtract or multiply operation and display result");
            }

        }


           

    }
}


This post has been edited by cats_rule: 01 March 2011 - 02:31 AM


Is This A Good Question/Topic? 0
  • +

Replies To: An object reference is required error. SOLVED

#2 cats_rule  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 21-November 10

Re: An object reference is required error. SOLVED

Posted 01 March 2011 - 02:32 AM

sorry was half asleep. noticed my MASSIVE ERROR !!! :-(
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1