Challenge at beginner course at c# programming number 5

Updated on December 28, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on December 18, 2017

is it okay that i used this code? because i didn’t know the Math.Abs

using System;

namespace challenge
{
    class Program
    {
        public static void Main(string[] args)
        {
            Random really = new Random ();
            int num1 = really.Next(1,11);
            int num2 = really.Next(1,11);
            Console.Write(“what is ” + num1 + ” multiplied to ” + num2 + “? :”);
            int read = Convert.ToInt32(Console.ReadLine());
            if (read == num1*num2){ 
                Console.WriteLine(“that is correct”);}
            else if (num1*num2-read == 1) {Console.WriteLine(“you are very very close”);}
            else if (num1*num2-read == -1) {Console.WriteLine(“you are very very close”);}
            else if (num1*num2-read == 2) {Console.WriteLine(“you are very close”);}
            else if (num1*num2-read == -2) {Console.WriteLine(“you are very close”);}
            else if (num1*num2-read == 3) {Console.WriteLine(“you are close”);}
            else if (num1*num2-read == -3) {Console.WriteLine(“you are close”);}
            else if (num1*num2-read == 4) {Console.WriteLine(“you are not very far away from answer”);}
            else if (num1*num2-read == -4) {Console.WriteLine(“you are not very far away from answer”);}
            else {Console.WriteLine (“THE ANSWER IS NOT NEAR”);}
            
            Console.Write(“Press any key to continue . . . “);
            Console.ReadKey(true);
        }
    }
}

  • Liked by
Reply
0 on December 28, 2017

I do not know what you will use Math.Abs for but it just gives you the positive value of a number.

example:

Console.Write(Math.Abs(-4)); // output is 4

Console.Write()Math.Abs(3); // output is 3

  • Liked by
Reply
Cancel