problem using

+1 Arnab Banerjee · June 16, 2015

  1. namespace program1

  2. {

  3.     class Program

  4.     {

  5.         static void Main(string[] args)

  6.         {

  7.             string number;

  8.             Console.WriteLine("Please enter your lucky number (With in the range of 50) ");

  9.             number = Console.ReadLine();

  10.             int x = int.Parse(number);

  11.            

  12.             string message = "";

  13.            

  14.             if (x <= 10)

  15.             {

  16.                 if (x % 3 == 0)

  17.                 

  18.                     message = "You won a cricket bat";

  19.                 

  20.                 else 

  21.                     message = "you haven't won anything";

  22.             }

  23.             if(11 <=x <= 20)

  24.             {

  25.                 message = "you won a cricket ball ";

  26.             }

  27.             Console.WriteLine(message);

  28.             Console.ReadLine();

  29.         }

  30.     }

  31. }

  32. I got the problem in bold &  underlined line (line o. 23)


Post a Reply

Replies

Oldest  Newest  Rating
0 Arnab Banerjee · June 17, 2015
yeah thanks cardinal,, the problem is solved no.
:)
+1 Cardinal Coog · June 16, 2015
I think what he is trying to do is check if x is between 11 and 20 inclusive.
If so, he should use:

if(x >= 11 && x <= 20)
{

}
+1 mike richardson · June 16, 2015
NP
0 Arnab Banerjee · June 16, 2015
Thanks mike & ariel
+1 ariel bitan · June 16, 2015
You are writing an expressions so you can't do 1<=x<=20 you need to do like Mike Richardson said
+2 mike richardson · June 16, 2015
Not sure what you are trying to do on line 23 but here are some suggestions.
if(x <= 11 && x <= 20)
  • 1

C#

107,130 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators