//编写一个控制台程序,要求用户输入5个大写字母,如果用户输入的信息不满足要求,提示帮助信息并要求重新输入。using System;
using System.Collections.Generic;
using System.Text;namespace HomeWork
{
    class HomeWork_9
    {
        public static void Main()
        {
            int i = 1;
            while(i<=5)
            {
                Console.WriteLine("Enter the {0} word: ",i);
                char a=(char)Console.Read();   //这样读字符对吗?
                if(a>='A'&& a<='Z')
                {
                    Console.WriteLine("The {0} word is {1}",i,a);
                    ++i;
                 }
                 else
                {
                    Console.WriteLine("{0} is not upper word!");
                    Console.WriteLine("Please enter it again.");
                }
            }        }
    }
}//是不是char a=(char)Console.Read();   //这样读字符对吗?
  //的问题呢?

解决方案 »

  1.   

    else
                    {
                        Console.WriteLine("{0} is not upper word!",a);
                        Console.WriteLine("Please enter it again.");
                        return;
                    }
    刚才我试了一下楼主的程序,可以执行啊,最好加个return;
      

  2.   

    static void Main(string[] args)
            {
                int i = 1;
                Console.WriteLine("Enter the 1 word ");
                while (i <= 5)
                {
                    //Console.WriteLine("Enter the {0} word ", i);
                    char a = (char)Console.Read();
                    if (a != 13 && a!=10)
                    {
                    if (a >= 'A' && a <= 'Z')
                    {
                        Console.WriteLine("The {0} word is {1}", i, a);
                        ++i;
                        if (i == 6)
                        {
                            Console.WriteLine("Input right!");
                            Console.ReadKey();
                        }
                        else
                        {
                            Console.WriteLine("Enter the {0} word ", i);
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} is not upper word!", a);
                        Console.WriteLine("Plase enter it again");
                        continue;
                    }
                    }
                }