http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3280|回复: 6

[学生提问] 求大神帮帮忙

[复制链接]
发表于 2014-9-15 13:52:42 | 显示全部楼层 |阅读模式
1金钱
用while循环语句编写  请输入班级的人数在5-35之间,然后依次输入学生的英语成绩,最后,计算班级平均成绩和总成绩



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-9-15 14:17:49 | 显示全部楼层
    class Program
    {
        static void Main(string[] args)
        {
            int stuCount = 0;
            Console.WriteLine("请输入学生人数(5-35之间):");
            while (true)
            {
                if (int.TryParse(Console.ReadLine(), out stuCount) == false || stuCount < 5 || stuCount > 35)
                {
                    Console.WriteLine("请输入学生人数(5-35之间):");
                }
                else
                {
                    break;
                }
            }

            int stepCount = 1;
            float sumScore = 0;
            while (stepCount <= stuCount)
            {
                Console.WriteLine("请输入第" + stepCount + "个学生的英语成绩:");
                float score = 0;
                while (true)
                {
                    if (float.TryParse(Console.ReadLine(), out score) == false)
                    {
                        Console.WriteLine("请输入正确的数字。");
                        Console.WriteLine("请输入第" + stepCount + "个学生的英语成绩:");
                    }
                    else
                    {
                        break;
                    }
                }
                stepCount++;
                sumScore += score;
            }

            Console.WriteLine("平均成绩:" + (sumScore / stepCount));
            Console.WriteLine("总成绩:" + sumScore);
            Console.ReadKey();
        }
    }
回复

使用道具 举报

发表于 2014-9-15 14:19:49 | 显示全部楼层
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //人数
            int n = 5;
            //总
            int sum = 0;
            //平均
            int avg = 0;
            int i = n;
            while (i > 0)
            {
                Console.WriteLine("请输入第{0}个人的成绩", n);
                int r = Convert.ToInt32(Console.ReadLine());
                i--;
                sum += r;
            }
            //计算机平均
            avg = sum / n;
            Console.WriteLine("总成绩:{0}\t平均成绩:{1}", sum,avg);
            Console.ReadLine();
        }
    }
}



QQ截图20140915142213.jpg
回复

使用道具 举报

 楼主| 发表于 2014-9-15 14:29:51 | 显示全部楼层
站长苏飞 发表于 2014-9-15 14:19
[mw_shl_code=csharp,true]using System;
using System.Collections.Generic;
using System.Linq;

要求的是5-35一个不定的数值。你这个是不是固定了。。
回复

使用道具 举报

发表于 2014-9-15 14:52:06 | 显示全部楼层
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Random ra = new Random();

            //人数
            int n = ra.Next(3, 35);
            //总
            int sum = 0;
            //平均
            int avg = 0;
            int i = n;
            while (i > 0)
            {
                Console.WriteLine("请输入第{0}个人的成绩", n);
                int r = Convert.ToInt32(Console.ReadLine());
                i--;
                sum += r;
            }
            //计算机平均
            avg = sum / n;
            Console.WriteLine("总成绩:{0}\t平均成绩:{1}", sum,avg);
            Console.ReadLine();
        }
    }
}
回复

使用道具 举报

 楼主| 发表于 2014-9-15 14:59:13 | 显示全部楼层
站长苏飞 发表于 2014-9-15 14:52
[mw_shl_code=csharp,true]using System;
using System.Collections.Generic;
using System.Linq;

谢谢。
回复

使用道具 举报

发表于 2014-9-15 17:17:12 | 显示全部楼层
养成一个好习惯
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-16 18:13

© 2014-2021

快速回复 返回顶部 返回列表