projects

Projects Gallery

Follow the story

Tabitha

class MainClass
{
public static void Main(string[] args)
{
bool keepGoing = true;
int savedValue = 0;
do
{
Console.WriteLine("Provide the frist value:");
string firstInput = Console.ReadLine().ToUpper();
int firstValue = 0;
if (firstInput == "MR")
{
firstInput = savedValue.ToString();
}
bool isNumeric = int.TryParse(firstInput, out firstValue);
while (!isNumeric)
{
Console.WriteLine("Not a number, please provide a value: "); firstInput = Console.ReadLine(); isNumeric = int.TryParse(firstInput, out firstValue); } Console.WriteLine("Provide an operation (+, -, *, /):"); string operationValue = Console.ReadLine(); while (operationValue != "+" && operationValue != "-" && operationValue != "*" && operationValue != "/") { Console.WriteLine("Not a supported operation, please provide an operation (+, -, *, /): "); operationValue = Console.ReadLine(); } Console.WriteLine("Provide second value: "); string secondInput = Console.ReadLine().ToUpper(); int secondValue = 0; if (secondInput == "MR") { secondInput = savedValue.ToString(); } bool isNumeric2 = int.TryParse(secondInput, out secondValue); while (!isNumeric2) { Console.WriteLine("Not a number, please provide second value: "); secondInput = Console.ReadLine(); isNumeric2 = int.TryParse(secondInput, out secondValue); } int total = 0; switch (operationValue) { case "+": total = firstValue + secondValue; break; case "-": total = firstValue - secondValue; break; case "*": total = firstValue * secondValue; break; case "/": total = firstValue / secondValue; break; defult: Console.WriteLine("Invalid operation value"); } Console.WriteLine("Total = " + total); Console.Write("Would you like to do something else (yes, no, save)? "); string finalInput = Console.ReadLine().ToUpper(); switch(finalInput) { case "No": keepGoing = false; break; case "Yes": break; case "Save": savedValue = total; break; defult: break; } } while (keepGoing); } }}