I'm working on an arithmetic program, and i'm trying to make it validate the user inputs than do the math in a separate class. Problem is I can't get the ints to the arithmetic class after validation and i'm not sure why. Here is the code.
static void Main(string[] args)
{
Console.WriteLine("Enter the first integer");
string numberOne = Console.ReadLine();
Console.WriteLine("Enter the second integer");
string numberTwo = Console.ReadLine();
Console.WriteLine("Enter the third integer");
string numberThree = Console.ReadLine();
Console.WriteLine("Enter the fourth integer");
string numberFour = Console.ReadLine();
Console.WriteLine("Enter the fifth integer");
string numberFive = Console.ReadLine();
Validate validate = new Validate();
validate.ValidateMethod();
}
}
}
public void ValidateMethod()
{
string line = Console.ReadLine();
int numberOne;
int numberTwo;
int numberThree;
int numberFour;
int numberFive;
if (int.TryParse(line, out numberOne))
{
if (int.TryParse(line, out numberTwo))
{
if (int.TryParse(line, out numberThree))
{
if (int.TryParse(line, out numberFour))
{
if (int.TryParse(line, out numberFive))
{
Arithmetic arithmetic = new Arithmetic();
arithmetic.ArithmeticMethod();
}
}
}
}
}
else
{
Console.WriteLine("The entered integer is not valid.");
}
}
public class Arithmetic
{
public void ArithmeticMethod()
{
int numberOne;
int numberTwo;
int numberThree;
int numberFour;
int numberFive;
numberOne = Convert.ToInt32(Console.ReadLine());
numberTwo = Convert.ToInt32(Console.ReadLine());
numberThree = Convert.ToInt32(Console.ReadLine());
numberFour = Convert.ToInt32(Console.ReadLine());
numberFive = Convert.ToInt32(Console.ReadLine());
numberOne = Validate.numberOne;
Sum(numberOne, numberTwo, numberThree, numberFour, numberFive);
Average(numberOne, numberTwo, numberThree, numberFour, numberFive);
Product(numberOne, numberTwo, numberThree, numberFour, numberFive);
SmallestNumber(numberOne, numberTwo, numberThree, numberFour, numberFive);
LargestNumber(numberOne, numberTwo, numberThree, numberFour, numberFive);
}
public static int Sum(int numberOne, int numberTwo, int numberThree, int numberFour, int numberFive)
{
int sum;
sum = numberOne + numberTwo + numberThree + numberFour + numberFive;
Console.WriteLine($"the sum of the integers is {sum}");
return sum;
}
public static double Average(int numberOne, int numberTwo, int numberThree, int numberFour, int numberFive)
{
int average;
int sum;
sum = numberOne + numberTwo + numberThree + numberFour + numberFive;
average = sum / 5;
Console.WriteLine($"the average of the integers is {average}");
return average;
}
public static int Product(int numberOne, int numberTwo, int numberThree, int numberFour, int numberFive)
{
int product;
product = numberOne * numberTwo * numberThree * numberFour * numberFive;
Console.WriteLine($"the product of the integers is {product}");
return product;
}
The specific error I get is "'Validate' does not contain a definition for 'number one'"
What I have tried:
things suggested from similiar questions on this site and others