Frank

Frank

  • NA
  • 16
  • 22.7k

How do I get a program to loop back through the code?

Feb 5 2011 9:09 PM
So I'm making a calculator and I've got it done so far but I'm having trouble making the code loop back through so the user can type new numbers to Add, Subtract, Divide, Multiply. Simple stuff so far because I'm new to C# but anyways here's what I have so far.

I keep getting two errors saying "Operator '||' cannot be applied to operands of type 'bool' and 'string' "

 if (userinput == "+")
{

 Console.Clear();


 Console.WriteLine("Enter The First Number You Would Like To Add: ");


 Add1 = Int32.Parse(Console.ReadLine());


 Console.WriteLine("Enter The Second Number You Would Like To Add: ");


 Add2 = Int32.Parse(Console.ReadLine());


 Console.WriteLine("The Answer Is: {0} ", Add1 + Add2);


 while (true)

{

 Console.WriteLine("Would You Like To Do Another Calculation? (Y) Yes, (N) No.");

 Console.ReadLine();

 if (userinput == "y" || "Y") // This if and else if is where the errors are.

{

  continue;

}

 else if (userinput == "n" || "N")

{

  break;

}

}

}

Answers (7)