Skip to content

Instantly share code, notes, and snippets.

@Y0lan
Created January 19, 2021 14:08
Show Gist options
  • Save Y0lan/21beb19681ce88b05273370a5c367f7a to your computer and use it in GitHub Desktop.
Save Y0lan/21beb19681ce88b05273370a5c367f7a to your computer and use it in GitHub Desktop.
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