I am new to C# and I am trying to make a calculator. In Python(which I am more familiar with), You just import mathand then write out what it is you want to do with math.
But with C#, this is my code:
using system; namespace Calculator { class MainClass { public static void Main(string[] args) { divide(2,3); } public static void add(int num01, int num02) { Console.WriteLine("The result is " + num01+num02); Console.ReadKey(); } public static void multiply(int num01, int num02) { Console.WriteLine("The result is " + num01 * num02); Console.ReadKey(); } public static void divide(double num01, double num02) { Console.WriteLine("The result is " + num01 / num02); Console.ReadKey(); } public static void subtract(int num01, int num02) { Console.WriteLine("The result is " + num01 - num02); Console.ReadKey(); } } } And it firstly gives me 23 if I try to add, and throws a syntax error( Operator '-' cannot be applied to operands of type 'string' and 'int'.) if I try to subtract.
I'm only new to this language so I'm probably making some silly mistakes.
string. You need to get the values asintfirst."The result is " + num01 - num02is like("The result is " + num01) - num02; the number gets concatenated to the string first, and then the subtraction happens. (It associates left-to-right.) Use parentheses to change that."Result = " + 4 -2"as "Result = 2"?