Function values

I thought if i wrote a function to declare the sum procedure i wanted to know why i have to assign varibles to these new object i created, I wanted to know how do i input my own values and return the sum...I get the error saying cannot convert string to type int..Any Help out there?!?!?Big SmileIdea

using System;

class Add

{

publicint x;

publicint y;

publicint sum;

publicint getsum()

{

int thesum;

thesum = x + y;

return thesum;

}

class MathA

{

staticvoid Main()

{

Add num1 =new Add();

Add num2 =new Add();

Add sum =new Add();

num1.x = 0;

num2.y = 0;

sum.sum = num1.x + num2.y;

Console.WriteLine("Enter two numbers");

Console.Write("Enter first number");

num1.x = Console.ReadLine();

Console.Write("Enter 2nd number");

num2.y = Console.ReadLine();

Console.WriteLine("The answer is {0}", sum.sum);

Console.WriteLine("Press enter to continue");

Console.ReadLine();

}

}

}

[2319 byte] By [Dpowers] at [2007-12-16]
# 1
Hi,
I think the readline method of console returns a string. So you'll have to parse it.

num2.x = int.parse(Console.Readline());

As I notice your program tends to add 2 numbers. Click HERE for a code snippet.
cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...