If statement help [SOLVED]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
mattykins
Posts: 203
Joined: Sun Jan 15, 2012 10:15 pm

If statement help [SOLVED]

Post 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
Last edited by mattykins on Mon Jan 16, 2012 2:50 am, edited 1 time in total.
User avatar
mattykins
Posts: 203
Joined: Sun Jan 15, 2012 10:15 pm

Re: If statement help

Post 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.
Post Reply

Return to “Beginner Help and Support”