Math.Abs statement in C#

maths-question-closeness

Here I took the user answer and subtract the correct answer from it in the parenthesis to apply it to the closeness of the user’s answer. For example, if the user was asked what is 2*8 and the user said 15, the application would perform the subtraction 15 – 16 = -1.

The Math.Abs statement converts any negative number to a positive.

So when seeing 15-16= -1 and the Math.Abs statement converts this to 1, the application can read that the user was 1 away from the correct answer.

Here if else statements can be used to inform the user how close they were to the correct answer, by saying if diff == 1 (being the closest), else if diff <= 10  (being fairly close) and else (being not close at all).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s