J
JackMcCann
Guest
i'm new to c# i've been making a simple calculator to test my skills in c# and i was wondering is there a way to make the console to restart the console program from the first line from the start when specified.
Console.WriteLine("Do you wish to continue? type yes to continue and no to exit the program");
consoleContinue = Console.ReadLine();
if (consoleContinue == "yes")
{
}
else
{
break;
}
this is the if and else statements i want to use to do this. i want the console to start over from line 1 when consoleContinue == "yes" but i don't know how to do this. any suggestions on how i could get the console to start over from line 1 without the console having to be closed then reopened? the current program looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Calculator
{
class Class1
{
static void Main(string[] args)
{
int num1 = 0;
int num2 = 0;
double answer = 0.00;
string sumType = " ";
string consoleContinue = " ";
Console.WriteLine("please enter your first value");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("please enter your second value");
num2 = Convert.ToInt32(Console.ReadLine());
while (true)
{
Console.WriteLine("would you like to add, subtract, multiply or divide?");
Console.WriteLine("alternitavely type quit to exit the program");
sumType = Console.ReadLine();
if (sumType == "add")
{
answer = (num1 + num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "subtract")
{
answer = (num1 - num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "multiply")
{
answer = (num1 * num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "divide")
{
answer = (num1 / num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "quit")
{
break;
}
else
{
Console.WriteLine("please enter a valid sum type");
}
Console.WriteLine("Do you wish to continue? type " + "yes" + " to continue and " + "no" + " to exit the program");
consoleContinue = Console.ReadLine();
if (consoleContinue == "yes")
{
}
else
{
break;
}
}
}
}
}
Continue reading...
Console.WriteLine("Do you wish to continue? type yes to continue and no to exit the program");
consoleContinue = Console.ReadLine();
if (consoleContinue == "yes")
{
}
else
{
break;
}
this is the if and else statements i want to use to do this. i want the console to start over from line 1 when consoleContinue == "yes" but i don't know how to do this. any suggestions on how i could get the console to start over from line 1 without the console having to be closed then reopened? the current program looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Calculator
{
class Class1
{
static void Main(string[] args)
{
int num1 = 0;
int num2 = 0;
double answer = 0.00;
string sumType = " ";
string consoleContinue = " ";
Console.WriteLine("please enter your first value");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("please enter your second value");
num2 = Convert.ToInt32(Console.ReadLine());
while (true)
{
Console.WriteLine("would you like to add, subtract, multiply or divide?");
Console.WriteLine("alternitavely type quit to exit the program");
sumType = Console.ReadLine();
if (sumType == "add")
{
answer = (num1 + num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "subtract")
{
answer = (num1 - num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "multiply")
{
answer = (num1 * num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "divide")
{
answer = (num1 / num2);
Console.WriteLine("{0:0.00}", answer);
}
else if (sumType == "quit")
{
break;
}
else
{
Console.WriteLine("please enter a valid sum type");
}
Console.WriteLine("Do you wish to continue? type " + "yes" + " to continue and " + "no" + " to exit the program");
consoleContinue = Console.ReadLine();
if (consoleContinue == "yes")
{
}
else
{
break;
}
}
}
}
}
Continue reading...