- Joined
- Feb 8, 2004
Hi all,
I used to do a lot of programming waaaaay back with commodore 64 BASIC and now I am just starting a course in C# (visual studio), we are making simple console applications. Im stuck on a problem. I'm trying to make a program that will calls on a subroutine to display a short list of options then input a choice from the user and return that value to the main body of the program. the subroutine works fine, but does not return the value of the variable to the main body of the program. This was really easy in BASIC and seems really hard in C#. I'm including the program I have so far.
using System;
class MainBodyOfProgram
{
static void Main (string [] args)
{
Console.WriteLine("Welcome to the calculator\n");
SubRoutine1 menu = new SubRoutine1(); //compiles subroutine1 for use
menu.DisplayMenu(); // displays the menu choices and gets input choice from user
Console.WriteLine("You chose option: {0}", a);
}
}
// start of subroutine1, display a menu, user selects a choice and subroutine puts it to variable 'a'
class SubRoutine1
{
public void DisplayMenu()
{
int a = 0;
Console.WriteLine("\n\nCalculator Menu");
Console.WriteLine("1)\tAdd");
Console.WriteLine("2)\tSubtract");
Console.WriteLine("3)\tMultiply");
Console.WriteLine("4)\tDivide");
Console.WriteLine("5)\tModulous");
Console.WriteLine("6)\tQuit");
Console.WriteLine("------------------------------------");
Console.Write("Enter Your Selection [1-6]: ");
a = Convert.ToInt32(Console.ReadLine());
}
}
I used to do a lot of programming waaaaay back with commodore 64 BASIC and now I am just starting a course in C# (visual studio), we are making simple console applications. Im stuck on a problem. I'm trying to make a program that will calls on a subroutine to display a short list of options then input a choice from the user and return that value to the main body of the program. the subroutine works fine, but does not return the value of the variable to the main body of the program. This was really easy in BASIC and seems really hard in C#. I'm including the program I have so far.
using System;
class MainBodyOfProgram
{
static void Main (string [] args)
{
Console.WriteLine("Welcome to the calculator\n");
SubRoutine1 menu = new SubRoutine1(); //compiles subroutine1 for use
menu.DisplayMenu(); // displays the menu choices and gets input choice from user
Console.WriteLine("You chose option: {0}", a);
}
}
// start of subroutine1, display a menu, user selects a choice and subroutine puts it to variable 'a'
class SubRoutine1
{
public void DisplayMenu()
{
int a = 0;
Console.WriteLine("\n\nCalculator Menu");
Console.WriteLine("1)\tAdd");
Console.WriteLine("2)\tSubtract");
Console.WriteLine("3)\tMultiply");
Console.WriteLine("4)\tDivide");
Console.WriteLine("5)\tModulous");
Console.WriteLine("6)\tQuit");
Console.WriteLine("------------------------------------");
Console.Write("Enter Your Selection [1-6]: ");
a = Convert.ToInt32(Console.ReadLine());
}
}