Skip to content

Commit 3d20921

Browse files
author
Scott Baldwin
committed
Add User Input
1 parent 0b50979 commit 3d20921

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/ComplexCalculator/Program.cs

+35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,41 @@ class Program
66
{
77
static void Main(string[] args)
88
{
9+
Console.WriteLine("This program adds 2 complex numbers");
10+
ComplexNumber c1 = new ComplexNumber
11+
{
12+
Real = ReadDouble("Enter Real Part of first complex number"),
13+
Imaginary = ReadDouble("Enter Imaginary part of first complex number")
14+
};
15+
ComplexNumber c2 = new ComplexNumber
16+
{
17+
Real = ReadDouble("Enter Real Part of second complex number"),
18+
Imaginary = ReadDouble("Enter Imaginary part of second complex number")
19+
};
20+
21+
var c3 = c1.Add(c2);
22+
23+
Console.WriteLine("{0} + {1} = {2} with modulous {3}", c1, c2, c3, c3.Modulous());
24+
}
25+
26+
private static double ReadDouble(string message)
27+
{
28+
double val;
29+
string s;
30+
bool success = false;
31+
do
32+
{
33+
Console.Write(message + ":");
34+
s = Console.ReadLine();
35+
success = double.TryParse(s, out val);
36+
if (!success)
37+
{
38+
Console.WriteLine("ERROR please try again.");
39+
}
40+
} while (!success);
41+
42+
return val;
43+
944
}
1045
}
1146
}

0 commit comments

Comments
 (0)