views:

47

answers:

2

Hello, I'm new to programming and am taking a C# class. I am getting compiler error CS1001 when I try to write this program.

I read the Compiler Error description (link below), but I'm really not getting it. What am I doing wrong?

http://msdn.microsoft.com/en-us/library/b839hwk4.aspx

Here is my source code:

using System;

public class InputMethodDemoTwo

{ public static void Main()

{

  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 first, out second)

// The error is citing the line above this note.

{

  one = DataEntry("first"); 

  two = DataEntry("second");

}

  public static void DataEntry(out int one, out int two)

  {

     string s1, s2;

     Console.Write("Enter first integer ");

     s1 = Console.ReadLine();

     Console.Write("Enter second integer ");

     s2 = Console.ReadLine();

     one = Convert.ToInt32(s1);

     two = Convert.ToInt32(s2);

  }

}

According to the instructions, I'm supposed to have a method b (InputData) which pulls statements from method c (DataEntry)... Here are the instructions:

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

one = DataEntry("first");

two = DataEntry("second");

Save the new program as InputMethodDemo2.cs."

The InputMethodDemo they are referring to is the same program, except that it calls only one method (the InputMethod) instead of two.

The text I referred to above is "Microsoft® Visual C#® 2008, An Introduction to Object-Oriented Programming, 3e, Joyce Farrell"

Any advice/ help would be greatly appreciated.

+2  A: 

Change

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

to

public static void InputMethod(out DataEntry first, out DataEntry second)
{
  first = DataEntry("first"); 
  second = DataEntry("second");
}

You haven't provided the type of the arguments. Also, your arguments are called first and second, not one and two.

Jakub Konecki
This resulted in another compiler error...
Nooob
+1  A: 

This is what you are expected to do:

using System;

public class InputMethodDemoTwo
{
    public static void Main()
    {

        int first, second;

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

    public static void InputMethod(out int first, out int second)
    //Data type was missing here
    {
        first = DataEntry("first");
        second = DataEntry("second");
    }

    public static int DataEntry(string method)
    //Parameter to DataEntry should be string
    {
        int result = 0;
        if (method.Equals("first"))
        {
            Console.Write("Enter first integer ");
            Int32.TryParse(Console.ReadLine(), out result);

        }
        else if (method.Equals("second"))
        {
            Console.Write("Enter second integer ");
            Int32.TryParse(Console.ReadLine(), out result);
        }
        return result;
    }
}
anivas
Thank you for your help
Nooob
That takes care of this week's homework. Available next week?
Hans Passant