Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Izzatilla Karimov
Izzatilla Karimov
9,284 Points

Simple Math

If I prompt the user for the number and the operator what method would be used to evaluate a simple math like 5 + 5... another words user puts in a solution to solve and the program has to solve it. I already asked for the numbers and the operator but i cant get it to evaluate it. Please help!

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi! I think your best bet might be to use a switch statement and switch on the operator. Then you could use that to evaluate the two numbers coming in.

Hope this helps! :sparkles:

Izzatilla Karimov
Izzatilla Karimov
9,284 Points

Hi! Thank you for your answer, I don't know much about switch statement yet, but I think switch statement is unnecessary, because user is putting in random operators and random numbers. If I can store that random operator in a ( var ) maybe then i can probably do var answer = num1 + (operator) + num2;