-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_slightly_more_advanced_calculator.cs
55 lines (39 loc) · 1.45 KB
/
A_slightly_more_advanced_calculator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
namespace Calculator
{
class Program {
static void Main(){
int num1;
int num2;
int result;
string answer;
Console.WriteLine("Hello! Welcome to our calculator!");
Console.WriteLine("Please enter your first number: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Now enter your second number: ");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("What type of operation would you like to do?");
Console.WriteLine("Press 'a' for addition, 's' for subtraction, 'm' for multiplication, and any other key for division.");
answer = Console.ReadLine(); // no need to cast this from being a string.
if (answer == "a")
{
result = num1 + num2;
}
else if (answer == "s")
{
result = num1 - num2;
}
else if (answer == "m")
{
result = num1 * num2;
}
else // if we used an else it statement, then nothing would actually be calculated (it seems?)
{
result = num1 / num2;
}
Console.WriteLine("The result is: " + result);
Console.WriteLine("Thank you for using this calculator program.");
Console.ReadKey();
}
}
}