2
Answers

I need help with methods

Prime b

Prime b

12y
1.5k
1
So this is the problem

Th e InputMethod() in the InputMethodDemo program in
Figure 8-5 contains repetitive code that prompts the user
and retrieves integer values. Rewrite the program so the
InputMethod() calls another method to do the work. Th e
rewritten InputMethod() will need to contain only two
statements:

one = DataEntry("fi rst");
two = DataEntry("second");
=======================================================
The original problem(figure 8-5) looks like this

 static void Main(string[] args)
        {
            int first, second;

           InputMethod(out first, out second);
           Console.WriteLine("After InputMethod first is {0}", first);
           Console.WriteLine("and second is {0}", second);

        }
        public static void InputMethod(out int one, out int two)
        {
            string s1, s2;
            Console.WriteLine("Enter first integer: ");
            s1 = Console.ReadLine();
            Console.WriteLine("Enter second integer: ");
            s2 = Console.ReadLine();

            one = Convert.ToInt32(s1);
            two = Convert.ToInt32(s2);
        }


=======================================================

This is me trying solve this:

        static void Main(string[] args)
        {
            int first, second;

            DataEntry(out first, out second);
            Console.WriteLine("After", first);
            Console.WriteLine("After", second);

        }
        public static void InputMethod(out int one, out int two)
        {
            one = DataEntry("firts");
            two = DataEntry("second");
        }

       
      
        public static void DataEntry(out int one, out int two)
        {
            string s1, s2;
            Console.WriteLine("Enter first integer: ");
            s1 = Console.ReadLine();
            Console.WriteLine("Enter second integer: ");
            s2 = Console.ReadLine();

            one = Convert.ToInt32(s1);
            two = Convert.ToInt32(s2);


BUT IT TELLS ME "No overload for method "DataEntry" takes 1 arguments. Does that mean I have to make second method name DataEntry?!



Answers (2)