建立的控制檯專案。你把程式碼複製到主函數里。Random r = new Random(); int num = r.Next(1, 101);//產生隨機數賦給num int count = 0;//count用來統計猜測次數 while (count<10) { string s = Console.ReadLine(); if (s == num.ToString()) { count++; break; } else { count++; } } if (count <=4) { Console.WriteLine("很棒"); } if (count <=7 && count>4) { Console.WriteLine("很好"); } if (count>7&&count<=10) { Console.WriteLine("一般"); } if(count>10) { Console.WriteLine("太差"); } Console.Read();
建立的控制檯專案。你把程式碼複製到主函數里。Random r = new Random(); int num = r.Next(1, 101);//產生隨機數賦給num int count = 0;//count用來統計猜測次數 while (count<10) { string s = Console.ReadLine(); if (s == num.ToString()) { count++; break; } else { count++; } } if (count <=4) { Console.WriteLine("很棒"); } if (count <=7 && count>4) { Console.WriteLine("很好"); } if (count>7&&count<=10) { Console.WriteLine("一般"); } if(count>10) { Console.WriteLine("太差"); } Console.Read();