Created
January 19, 2021 14:08
-
-
Save Y0lan/21beb19681ce88b05273370a5c367f7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
namespace kata.App | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string line; | |
int number = 0; | |
bool first = true; | |
System.IO.StreamReader file = | |
new System.IO.StreamReader("/home/yolan/RiderProjects/kata/src/kata.App/numbers.txt"); | |
System.Console.Write("Enter '+' or '*': "); | |
string op = Console.ReadLine(); | |
while ((line = file.ReadLine()) != null) | |
{ | |
if (op.Equals("*")) number = first ? Int32.Parse(line) : Int32.Parse(line) * number; | |
else number = first ? Int32.Parse(line) : Int32.Parse(line) + number; | |
if (first) | |
{ | |
System.Console.WriteLine(line); | |
first = false; | |
} | |
else | |
{ | |
if (op.Equals("*")) System.Console.WriteLine("*{0} (={1})", line, number); | |
else System.Console.WriteLine("+{0} (={1})", line, number); | |
} | |
} | |
file.Close(); | |
if (op.Equals("*")) | |
System.Console.WriteLine("-------\n" + | |
"total = {0} (multiplication)", number); | |
else | |
System.Console.WriteLine("-------\n" + | |
"total = {0} (addition)", number); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment