Page 1 of 1

If statement help [SOLVED]

Posted: Mon Jan 16, 2012 1:46 am
by mattykins
Sorry if this isn't the right topic, please let me know if it isn't and i will move the post to the right topic.

So i'm trying to build a basic calculator in C# to test myself, and so far i have this code

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("1. Addition");
            Console.WriteLine("2.Subtraction");
            Console.WriteLine("3.Multiplication");
            Console.WriteLine("4.Division");
            string menuchoice = Console.ReadLine();

            if (menuchoice = 1)
            {

            }
            if (menuchoice = 2)
            {

            }
            if (menuchoice = 3)
            {

            }
            if (menuchoice = 4)
            {

            }
        }
    }
}
I'm going to have each of the if statements call its respective class, for example if the user inputs "1" It will call the addition class.
However the problem i'm having is that i'm getting this error
"
Error 1 Cannot implicitly convert type 'int' to 'string' C:\Users\Matt\AppData\Local\Temporary Projects\ConsoleApplication1\Program.cs 18 30 ConsoleApplication1

"
What does it mean? And how should I go about fixing it.
Thanks in advanced!
~Matt

Re: If statement help

Posted: Mon Jan 16, 2012 2:49 am
by mattykins
Solved it! I figured it out after a good deal of googling.
I had to use the Convert.ToInt32 command When i was using Console.Readline(); in order to make the user input an integer.