Hi. I started last week trying to learn C#, and think I've gotten a good way already. I learned about classes today!
I plan on one day being a game developer.
Anyway, I need some help with a calculator I tried to make in Command Console(?), when I type in the two numbers, it won't calculate, the answer is blank!
Can someone help me? (Sorry if this seems like a stupid question.)
I plan on one day being a game developer.
Anyway, I need some help with a calculator I tried to make in Command Console(?), when I type in the two numbers, it won't calculate, the answer is blank!
Can someone help me? (Sorry if this seems like a stupid question.)
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Write your first number:");
string numOne = Console.ReadLine();
Console.WriteLine("Write your second number: ");
string numTwo = Console.ReadLine();
int numberOne = Convert.ToInt32(numOne);
int numberTwo = Convert.ToInt32(numTwo);
Console.WriteLine("+, -, / or *?");
string method = Console.ReadLine();
switch (method)
{
case "+":
Plus(numberOne, numberTwo);
Console.ReadLine();
break;
case "-":
Minus(numberOne, numberTwo);
break;
Console.ReadLine();
break;
case "*":
Multiply(numberOne, numberTwo);
Console.ReadLine();
break;
case "/":
Division(numberOne, numberTwo);
Console.ReadLine();
break;
default:
Console.WriteLine("Error!");
break;
}
}
static int Multiply(int a, int b)
{
int answer = a * b;
return answer;
}
static int Minus(int a, int b)
{
int answer = a - b;
return answer;
}
static int Plus(int a, int b)
{
int answer = a + b;
return answer;
}
static double Division(int a, int b)
{
if (a == 0) // This is just so that I won't get an error!
{
return 0;
}
else if (b == 0)
{
return 0;
}
else
{
double answer = a / b;
return answer;
}
}
}
}