store input +, * or / for an calculation.

Updated on December 30, 2019 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on December 29, 2019

I’ve searched around for this, it’s probably very common question but getting back to programming and not sure what to search for.

 

What I want to do is let let user to input addition, subtraction, multiplication or division and store this for an calculation.

 

is it possible to parse a string with only an arithmetic value to an int somehow?

 

or do I need to create an if statement or another switch statement?

 

 
switch (choiceSwitch)
 
{
case 1:
{
choice = "+";
break;
}
case 2:
{
choice = "*";
break;
}
case 3:
{
choice = "+";
break;
}
int result = num1 "choice" num2;
 
 

  • Liked by
Reply
1 on December 29, 2019

Easiest solution is to create an if-else condition, or another switch statement.
I’m not aware of any other way that would be worth looking into.

on December 30, 2019

Thanks for your reply, I was guessing that might be the case.

 

Show more replies
  • Liked by
Reply
Cancel