namespace Test
{
class Program
{
static void Main(string[] args)
{
int firstNum;
int secondNum; int secondNum; //Variables for equation
string operation;
int answer;
Console.WriteLine("Hello, welcome to Alex's basic calculator!");
Console.ReadLine();
Console.Write("Enter the first number in your basic equation: ");
firstNum = Convert.ToInt32(Console.ReadLine());
//User input for equation
Console.Write("Now enter your second number in the basic equation: ");
secondNum = Convert.ToInt32(Console.ReadLine());
Console.Write("Ok now enter your operation ( x , / , +, -) ");
operation = Console.ReadLine();
if (operation == "x")
{
answer = firstNum * secondNum;
Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNum / secondNum;
Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
Console.ReadLine();
}
//Getting answers
else if (operation == "+")
{
answer = firstNum + secondNum;
Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNum - secondNum;
Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("Sorry that is not correct format! Please restart!"); //Catch
Console.ReadLine();
}
}
}
}
namespace Test
class Program
{
static void Main(string[] args)
{
int firstNum;
int secondNum; //Variables for equation
string operation;
int answer;
Console.WriteLine("Hello, welcome to Alex's basic calculator!");
Console.ReadLine();
Console.Write("Enter the first number in your basic equation: ");
firstNum = Convert.ToInt32(Console.ReadLine()); //User input for equation
Console.Write("Now enter your second number in the basic equation: ");
secondNum = Convert.ToInt32(Console.ReadLine());
Console.Write("Ok now enter your operation ( x , / , +, -) ");
operation = Console.ReadLine();
if (operation == "x")
{
answer = firstNum * secondNum;
Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNum / secondNum;
Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
Console.ReadLine();
} //Getting answers
else if (operation == "+")
{
answer = firstNum + secondNum;
Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNum - secondNum;
Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("Sorry that is not correct format! Please restart!"); //Catch
Console.ReadLine();
}
}
}
}
namespace Test
{
class Program
{
static void Main(string[] args)
{
int firstNum;
int secondNum; //Variables for equation
string operation;
int answer;
Console.WriteLine("Hello, welcome to Alex's basic calculator!");
Console.ReadLine();
Console.Write("Enter the first number in your basic equation: ");
firstNum = Convert.ToInt32(Console.ReadLine());
//User input for equation
Console.Write("Now enter your second number in the basic equation: ");
secondNum = Convert.ToInt32(Console.ReadLine());
Console.Write("Ok now enter your operation ( x , / , +, -) ");
operation = Console.ReadLine();
if (operation == "x")
{
answer = firstNum * secondNum;
Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNum / secondNum;
Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
Console.ReadLine();
}
//Getting answers
else if (operation == "+")
{
answer = firstNum + secondNum;
Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNum - secondNum;
Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("Sorry that is not correct format! Please restart!"); //Catch
Console.ReadLine();
}
}
}
}
First Program (Simple Calculator)! Tips? Simple calculator in C#
Ok this is my first program ever.
It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example, if the user enters number 2 number 3 and tells it to multiply, it will display the answer as 6. I just want to know how this could be improved.
Could I have used loops or more advanced procedures to get the same output? Here is the code:
namespace Test
class Program
{
static void Main(string[] args)
{
int firstNum;
int secondNum; //Variables for equation
string operation;
int answer;
Console.WriteLine("Hello, welcome to Alex's basic calculator!");
Console.ReadLine();
Console.Write("Enter the first number in your basic equation: ");
firstNum = Convert.ToInt32(Console.ReadLine()); //User input for equation
Console.Write("Now enter your second number in the basic equation: ");
secondNum = Convert.ToInt32(Console.ReadLine());
Console.Write("Ok now enter your operation ( x , / , +, -) ");
operation = Console.ReadLine();
if (operation == "x")
{
answer = firstNum * secondNum;
Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNum / secondNum;
Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
Console.ReadLine();
} //Getting answers
else if (operation == "+")
{
answer = firstNum + secondNum;
Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNum - secondNum;
Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("Sorry that is not correct format! Please restart!"); //Catch
Console.ReadLine();
}
}
}
}
}
First Program (Simple Calculator)! Tips?
Ok this is my first program ever.
It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example if the user enters number 2 number 3 and tells it to multiply it will display the answer as 6. I just want to know how this could be improved.
Could I have used loops or more advanced procedures to get the same output? Here is the code:
namespace Test
class Program
{
static void Main(string[] args)
{
int firstNum;
int secondNum; //Variables for equation
string operation;
int answer;
Console.WriteLine("Hello, welcome to Alex's basic calculator!");
Console.ReadLine();
Console.Write("Enter the first number in your basic equation: ");
firstNum = Convert.ToInt32(Console.ReadLine()); //User input for equation
Console.Write("Now enter your second number in the basic equation: ");
secondNum = Convert.ToInt32(Console.ReadLine());
Console.Write("Ok now enter your operation ( x , / , +, -) ");
operation = Console.ReadLine();
if (operation == "x")
{
answer = firstNum * secondNum;
Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNum / secondNum;
Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
Console.ReadLine();
} //Getting answers
else if (operation == "+")
{
answer = firstNum + secondNum;
Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNum - secondNum;
Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("Sorry that is not correct format! Please restart!"); //Catch
Console.ReadLine();
}
}
}
}
Simple calculator in C#
It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example, if the user enters number 2 number 3 and tells it to multiply, it will display the answer as 6. I just want to know how this could be improved.
Could I have used loops or more advanced procedures to get the same output?
namespace Test
class Program
{
static void Main(string[] args)
{
int firstNum;
int secondNum; //Variables for equation
string operation;
int answer;
Console.WriteLine("Hello, welcome to Alex's basic calculator!");
Console.ReadLine();
Console.Write("Enter the first number in your basic equation: ");
firstNum = Convert.ToInt32(Console.ReadLine()); //User input for equation
Console.Write("Now enter your second number in the basic equation: ");
secondNum = Convert.ToInt32(Console.ReadLine());
Console.Write("Ok now enter your operation ( x , / , +, -) ");
operation = Console.ReadLine();
if (operation == "x")
{
answer = firstNum * secondNum;
Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNum / secondNum;
Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
Console.ReadLine();
} //Getting answers
else if (operation == "+")
{
answer = firstNum + secondNum;
Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNum - secondNum;
Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("Sorry that is not correct format! Please restart!"); //Catch
Console.ReadLine();
}
}
}
}
First Program (Simple Calculator)! Tips?
Ok this is my first program ever.
It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example if the user enters number 2 number 3 and tells it to multiply it will display the answer as 6. I just want to know how this could be improved.
Could I have used loops or more advanced procedures to get the same output? Here is the code:
namespace Test
class Program
{
static void Main(string[] args)
{
int firstNum;
int secondNum; //Variables for equation
string operation;
int answer;
Console.WriteLine("Hello, welcome to Alex's basic calculator!");
Console.ReadLine();
Console.Write("Enter the first number in your basic equation: ");
firstNum = Convert.ToInt32(Console.ReadLine()); //User input for equation
Console.Write("Now enter your second number in the basic equation: ");
secondNum = Convert.ToInt32(Console.ReadLine());
Console.Write("Ok now enter your operation ( x , / , +, -) ");
operation = Console.ReadLine();
if (operation == "x")
{
answer = firstNum * secondNum;
Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "/")
{
answer = firstNum / secondNum;
Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
Console.ReadLine();
} //Getting answers
else if (operation == "+")
{
answer = firstNum + secondNum;
Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
Console.ReadLine();
}
else if (operation == "-")
{
answer = firstNum - secondNum;
Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
Console.ReadLine();
}
else
{
Console.WriteLine("Sorry that is not correct format! Please restart!"); //Catch
Console.ReadLine();
}
}
}
}