Skip to content

Commit bb4e777

Browse files
committed
Enabled calculations on user's chosen amount of numbers
1 parent 094fcfe commit bb4e777

File tree

12 files changed

+44
-21
lines changed

12 files changed

+44
-21
lines changed

Calculator/Calculator/Program.cs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,50 @@ static void Main(string[] args)
2828
else
2929
operatorEntered = false;
3030
}
31+
32+
Console.WriteLine($"How many numbers do you want to {operatorSymbol}?");
33+
string userInput1 = Console.ReadLine();
34+
int numberOfNumbers = int.Parse(userInput1);
3135

3236
if (operatorEntered == true)
3337
{
34-
Console.WriteLine("Enter a number: ");
35-
string userInput1 = Console.ReadLine();
36-
double firstNumber = double.Parse(userInput1);
37-
38-
Console.WriteLine("Enter a second number: ");
39-
string userInput2 = Console.ReadLine();
40-
double secondNumber = double.Parse(userInput2);
41-
42-
double result = 0;
43-
44-
if (operatorSymbol == "+")
45-
result = firstNumber + secondNumber;
46-
else if (operatorSymbol == "-")
47-
result = firstNumber - secondNumber;
48-
else if (operatorSymbol == "/")
49-
result = firstNumber / secondNumber;
50-
else if (operatorSymbol == "x")
51-
result = firstNumber * secondNumber;
38+
double[] numbers = new double[numberOfNumbers];
39+
40+
for (int i = 0; i < numberOfNumbers; i++)
41+
{
42+
Console.WriteLine("Enter a number: ");
43+
string userInput2 = Console.ReadLine();
44+
double number = double.Parse(userInput2);
45+
numbers[i] = number;
46+
}
47+
48+
foreach (double number in numbers)
49+
{
50+
Console.WriteLine(number);
51+
}
52+
53+
double result = numbers[0];
54+
55+
for (int i = 1; i < numberOfNumbers; i++)
56+
{
57+
switch (operatorSymbol)
58+
{
59+
case "+":
60+
result += numbers[i];
61+
break;
62+
case "-":
63+
result -= numbers[i];
64+
break;
65+
case "x":
66+
result *= numbers[i];
67+
break;
68+
case "/":
69+
result /= numbers[i];
70+
break;
71+
default:
72+
break;
73+
}
74+
}
5275

5376
Console.WriteLine($"The answer to your calculation is: {result}");
5477
}
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
220 Bytes
Binary file not shown.

Calculator/Calculator/obj/Debug/net9.0/Calculator.AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[assembly: System.Reflection.AssemblyCompanyAttribute("Calculator")]
1414
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
1515
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
16-
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a935242fe9e28892f0980698f67db57ddd63431c")]
16+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+094fcfecfa2da4ab481ecea93f3a43e7a6418141")]
1717
[assembly: System.Reflection.AssemblyProductAttribute("Calculator")]
1818
[assembly: System.Reflection.AssemblyTitleAttribute("Calculator")]
1919
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18faebc9cd06b6266be4f950ddfb15c01a96a69ac05092d028c4a940e432ed0f
1+
63ea61418fc7743c32e039b2b1f2d58cc02c7d915e763e42beba601f9ff96eab
512 Bytes
Binary file not shown.
220 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"documents":{"C:\\Users\\hanna\\RiderProjects\\CSharpPreReading\\*":"https://raw.githubusercontent.com/hduns/CSharpPreReading/a935242fe9e28892f0980698f67db57ddd63431c/*"}}
1+
{"documents":{"C:\\Users\\hanna\\RiderProjects\\CSharpPreReading\\*":"https://raw.githubusercontent.com/hduns/CSharpPreReading/094fcfecfa2da4ab481ecea93f3a43e7a6418141/*"}}
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)