TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Prime b
NA
810
346.8k
I need help with methods
Jan 17 2012 6:40 PM
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?!
Reply
Answers (
2
)
Overloaded constructor in c#
Stuck again on methods