Stupid issue, i cant remember, I am brushing up on my C# so, if anyone can figure out what am I doing wrong and tell me that would be great.
Just a simple calculator which the equations with the variables in a different class called equations (sorry naming convention sucks). but it appears the error message on the answer1, what I want to do is have the user type in a for add, s for subtract etc etc, so i decided to use while loop until user enters correct letter, also how do you set it to where the user can enter a or A, s or S etc?
Thank you
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace practicecalc
{
class Program
{
static void Main(string[] args)
{
try
{
equations equat = new equations();
string answer1;
while (answer1 != "a" || answer1 != "s" || answer1 != "d" || answer1 != "m")
{
Console.WriteLine("type a for Add, s for Subtract, d for Divide, m for Multiply");
answer1 = Console.ReadLine();
}
Console.WriteLine("Enter the first number");
equat.Num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number");
equat.Num2 = Convert.ToInt32(Console.ReadLine());
if (answer1 == "a")
{
Console.WriteLine("Your Answer is " + equat.addvalues(equat.Num1, equat.Num2));
Console.ReadKey();
}
if (answer1 == "s")
{
Console.WriteLine("Your Answer is " + equat.subtractvalues(equat.Num1, equat.Num2));
Console.ReadKey();
}
if (answer1 == "d")
{
Console.WriteLine("Your Answer is " + equat.dividevalues(equat.Num1, equat.Num2));
Console.ReadKey();
}
if (answer1 == "m")
{
Console.WriteLine("Your Answer is " + equat.multiplyvalues(equat.Num1, equat.Num2));
Console.ReadKey();
}
}
catch(Exception )
{
MessageBox.Show("DO IT RIGHT IDIOT!! IT SAID NUMBERS, HOW SIMPLE CAN YOU GET!!");
}
}
}
}


Sign In
Create Account


Back to top









