美文网首页
第十次作业第二题

第十次作业第二题

作者: 孤独是种安全感_b7bf | 来源:发表于2018-12-05 18:47 被阅读0次

代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{/**
* 以表格的形式输出5笔购物金额及总金额
* 1.创建一个长度为5的 double类型数组,存储购物金额。
* 2.循环输入五笔购物金额, 并累加总金额。
* 3.利用循环输出五笔购物金额,最后输出总金额。
* */
try
{
Console.WriteLine("请输入会员本月的消费记录");
double[] money = new double[5];
double sum = 0;
//用户输入本月消费记录
for (int i = 0; i < money.Length; i++)
{
Console.WriteLine("请输入第{0}笔购物金额:", i + 1);
money[i] = Convert.ToDouble(Console.ReadLine());
sum += money[i];
}

                Console.WriteLine(@"序号          金额(元)");
            for (int i = 0; i < money.Length; i++)
            {
                Console.WriteLine(@"{0}          {1}", i+1, money[i]);    
            }
            Console.WriteLine(@"总金额          {0}",sum);
        }
        catch
        {
            Console.WriteLine("你输入的格式有误");
        }
      
        Console.ReadKey();
    }
}

}

效果

QQ图片20181205184516.png

相关文章

网友评论

      本文标题:第十次作业第二题

      本文链接:https://www.haomeiwen.com/subject/jrcwcqtx.html