Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

how would i make it so if i type "x" "x" will happen

mepermeper Member
edited June 25 in Programming

I'm trying to make a simple calculator so when I type a, s, m, or d it would go to the method I want it to go to but when I try to write "if ( a = Console.ReadLine()) {Addition();} it just says "Cannot implicitly convert type 'string' to 'bool'" but how would I do that?

here is my code

static void Start()

        {    

            string a = "a";

             Console.Write("type a for addition, s for subtraction, m for multiplication, or d for division: ");

             if ( a = Console.ReadLine() );

            {

                Addition();

            }

        }

im mostly just trying to say how would i use whatever i typed in an if statement


edit -i got it to work :)


static void Start()

        {   

            string asmd;

            string a = "a";

            string s = "s";

            string m = "m";

            string d = "d";

            

             Console.Write("type a for addition, s for subtraction, m for multiplication, or d for division: ");

            asmd = Console.ReadLine();

            if (asmd == a)

            {

                Addition();

            }

            else

            {

                Start();

            }

            if (asmd == s)

            {

                Subtraction();

            }

            else

            {

                Start();

            }

            if (asmd = m)

            {

                Multiplication();

            }

            else

            {

                Start();

            }

            if (asmd == d)

            {

                Division();

            }

            else

            {

                Start();

            }


        }

Answers

  • QuarkQuark Member

    You could have just written the chars under "" (say, "a" for addition) and checked directly instead of declaring so many variables (which is extremely memory inefficient).

Sign In or Register to comment.