- #1
TheDemx27
Gold Member
- 169
- 13
Just starting to learn C#. I just wrote this program to add two numbers and loops by looking up syntax etc. There HAS to be a more efficient way to do this.
Code:
using System;
public class Program
{
static void Main()
{
bool repeat = true;
while (repeat == true)
{
string x;
string y;
int xint;
int yint;
string useranswer;
Console.WriteLine("Enter 'X':");
x = Console.ReadLine();
xint = int.Parse(x);
Console.Clear();
Console.WriteLine("Enter 'Y':");
y = Console.ReadLine();
yint = int.Parse(y);
Console.Clear();
int answer = xint + yint;
Console.WriteLine("{0} + {1} = {2}", x, y, answer);
Console.ReadLine();
Console.WriteLine("Run again?: Y/N");
useranswer = Console.ReadLine();
Console.Clear();
if (useranswer == "y" || useranswer == "Y")
{
repeat = true;
}
else
{
repeat = false;
}
}
}
}