Access variable from different method

  • Thread starter Thread starter amusment5678
  • Start date Start date
A

amusment5678

Guest
I have just written a little calculator console program and I'm trying to access the checkIfComplete variable from a different method. Any answers?


using System;
namespace sll
{
class Program
{
int checkIfComplete = 0;

static void Main(string[] args)
{
calculator();

int checkIfComplete = 0;
if (checkIfComplete == 0) {

}
else {
calculator();
}
}

static void calculator() {
Console.WriteLine("Please choose your method of calculating: \nAdding, Subtracting, Multiplying or didviding");
string method = Console.ReadLine();
int checkIfComplete = 0;
if (method == "adding") {
Console.WriteLine("Input 2 numbers to add: ");
int numadd1 = Convert.ToInt32(Console.ReadLine());
int numadd2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The answer to " + numadd1 + " + " + numadd2 + " is " + (numadd1 + numadd2));
checkIfComplete++;
}
else if (method == "subtracting") {
Console.WriteLine("Input 2 numbers to subtract: ");
int numminus1 = Convert.ToInt32(Console.ReadLine());
int numminus2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The answer to " + numminus1 + " - " + numminus2 + " is " + (numminus1 - numminus2));
checkIfComplete++;
}
else if (method == "multiplying") {
Console.WriteLine("Input 2 numbers to multiply: ");
int numdiv1 = Convert.ToInt32(Console.ReadLine());
int numdiv2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The answer to " + numdiv1 + " * " + numdiv2 + " is " + (numdiv1 * numdiv2));
checkIfComplete++;
}
else if (method == "dividing") {
Console.WriteLine("Input 2 numbers to divide(Answers only in whole numbers): ");
int nummul1 = Convert.ToInt32(Console.ReadLine());
int nummul2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The answer to " + nummul1 + " / " + nummul2 + " is " + (nummul1/nummul2));
checkIfComplete++;
}


Console.ReadKey();
}



}
}


Continue reading...
 
Back
Top