03. Practice

Source: Internet
Author: User

  
 
  1. namespace _08.练习01
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //练习1:循环录入5个人的年龄并计算平均年龄,如果录入的数据出现负数或大于100,
  8. //立即停止输入并报错
  9. int avg = 0; //用来保存平均成绩.
  10. int score = 0; //用来保存每一次输入的成绩
  11. bool b = true; //用来反馈错误
  12. for (int i = 1; i <=5; i++)
  13. {
  14. Console.WriteLine("请输入第{0}个人的年龄:",i);
  15. b=int.TryParse(Console.ReadLine(),out score);
  16. if (b == false)
  17. {
  18. Console.WriteLine("你输入的不是年龄");
  19. break;
  20. }
  21. else if(score>100||score<0)
  22. {
  23. Console.WriteLine("你的出入超出范围!");
  24. break;
  25. }
  26. }
  27. Console.ReadKey();
  28. }
  29. }
  30. }



From for notes (Wiz)

03. Practice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.