-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
130 lines (107 loc) · 4.52 KB
/
Program.cs
File metadata and controls
130 lines (107 loc) · 4.52 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
/*
Console Calculator designed to ask a user for two numbers.
And thne ask the user if they want to add, subtract, multiply, or divide
then display the output.
*/
int userInput1 = 0;
int userInput2 = 0;
int userSelection = 0;
int total;
bool checkInput1 = false;
bool checkInput2 = false;
bool checkSelection = false;
string userRequest;
Console.WriteLine("This Calculator Program!");
//loop to check for correct input (first input)
while (!checkInput1)
{
Console.WriteLine("Please enter the first number: ");
var userInput1Check = Console.ReadLine();
checkInput1 = int.TryParse(userInput1Check, out userInput1);
if (!checkInput1)
{
Console.WriteLine("Please enter a numerical value!");
}
if (checkInput1 == false)
{
Console.WriteLine("Please enter 'Y' or 'Yes to continue or N or 'No' to exit.");
userRequest = Console.ReadLine();
if (userRequest == "N" || userRequest == "No")
{
Environment.Exit(0);
}
}
}
//loop to check for correct input (second input)
while (!checkInput2)
{
Console.WriteLine("Please enter the second number: ");
var userInput2Check = Console.ReadLine();
checkInput2 = int.TryParse(userInput2Check, out userInput2);
if (!checkInput2)
{
Console.WriteLine("Please enter a numerical value!");
}
if (checkInput2 == false)
{
Console.WriteLine("Please enter 'Y' or 'Yes to continue or N or 'No' to exit.");
userRequest = Console.ReadLine();
if (userRequest == "N" || userRequest == "No")
{
Environment.Exit(0);
}
}
}
//loop to check for correct input (third input)
while (!checkSelection)
{
Console.WriteLine("Please enter if you would like to (#):");
Console.WriteLine("1. Add\n2. Subtract\n3. Multiply \n4. Divide");
userSelection = Convert.ToInt32(Console.ReadLine());
if (userSelection == 1 || userSelection == 2 || userSelection == 3 || userSelection == 4)
{
checkSelection = true;
}
if (checkSelection == false)
{
Console.WriteLine("Selction must be between 1 - 4");
Console.WriteLine("Please enter 'Y' or 'Yes to continue or N or 'No' to exit.");
userRequest = Console.ReadLine();
if (userRequest == "N" || userRequest == "No")
{
Environment.Exit(0);
}
}
}
//Perform mathimatical operation
Console.WriteLine($"The numbers entered are {userInput1} and {userInput2} and option #{userSelection}");
if (userSelection == 1)
{
total = userInput1 + userInput2;
Console.WriteLine($"Adding the two numbers together = {total}");
}
else if (userSelection == 2)
{
total = userInput1 - userInput2;
Console.WriteLine($"Subtracting the two numbers together = {total}");
}
else if (userSelection == 3)
{
total = userInput1 * userInput2;
Console.WriteLine($"Multiplying the two numbers together = {total}");
}
else
{
total = userInput1 / userInput2;
Console.WriteLine($"Dividing the two numbers together = {total}.");
}
}
}
}