The name 'quit' does not exist in the current context
I don't understand why my method does not see the quit variable. Isn't the boolean quit a wide scope variable available to all methods?
I tried putting it in a couple of places outside Main and inside main but I can not get a method to see it. Can someone explain to me what gives?
I get the error:
Error 1 An object reference is required for the nonstatic field, method, or property Program.quit'
bool
quit =true;static
void Main(string[] args){
do{
getChoice();
}
while (!quit);}
publicstaticvoid getChoice(){
quit =
IO.GetChar("Choose a)square root, b)floor, c)absolute value, d)Quit: y or n ");quit = (quit ==
'y');}
Ok, I've rewritten it. But I still have this problem:
The name 'inputNmbr' does not exist in the current context
Even if I take the variable and place it under class rather than the Main method, I still have an error. Thanks in advance for any explanation or advice..
using System;
using System.Collections.Generic;
using System.Text;
namespace TTTTT
{
class Program
{
static void Main(string[] args)
{
char quit = 'y';
char choice;
do
{
quit = getChoice(quit);
if (quit != 'n' || quit != 'y')
{
choice = quit;
inputNmbr = IO.GetDouble("What number do you wish?: ");
doMath(choice);
}
} while (quit == 'n');
}
static char getChoice(char quit)
{
quit = IO.GetChar("Choose a)square root, b)floor, c)absolute value, d)Quit - y or n: ");
//quit = (quit == 'y');
return quit;
}
static char doMath(char choice)
{
switch (choice) {
case 'a':
Console.WriteLine("inputNmbr = ", inputNmbr = Math.Pow(inputNmbr, 2.0));
break;
case 'b':
break;
case 'c':
break;
}
}
}
}

