At line number 16, it throws an unhandled exception!! please explain what’s wrong ?

Updated on June 10, 2018 in Challenges
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on June 9, 2018

namespace Rndom
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            start:
            Random obj = new Random();
            int num1 = obj.Next(1, 9);
            int num2 = obj.Next(10,21);
            Console.WriteLine(<span style="color: #db7100;”>”sum of two unique numbers\n”
<span style=”color: #222222;”>+num1+” “+num2+”  “+(num1+num2));
            char ch;
            Console.WriteLine(“If wannt to continue, press y”);
            ch = Convert.ToChar(Console.ReadKey());
            if(ch==‘y’)
            {
                goto start;
            }
            else
            {
                Console.WriteLine(“press any key to terminate”);
                Console.ReadKey();
            }

        }

    }
}

  • Liked by
Reply
1 on June 9, 2018

Playing with your code, this works:

start:
 Random obj = new Random();
 int num1 = obj.Next(1, 9);
 int num2 = obj.Next(10, 21);
 
// Pretty color change! 
Console.ForegroundColor = ConsoleColor.Blue;
  
 string ch;
 Console.WriteLine("If wannt to continue, press y");
 ch = Console.ReadKey().ToString().ToLower();
 if (ch =="y")
 {
    goto start;
 }
 else
 {
    Console.WriteLine("press any key to terminate");
    Console.ReadKey();
 }

Although, I have no idea what span style is. Why don’t you just assign a color normally to the Console? BTW, you should avoid using goto, it’s bad practice and should be avoided. 

on June 10, 2018

thank you!!!!

Show more replies
  • Liked by
Reply
Cancel