标题:怎么调用while语句内的变量值 想调用while语句的值在外面使用
只看楼主
徐夏语
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-11-14
 问题点数:0 回复次数:1 
怎么调用while语句内的变量值 想调用while语句的值在外面使用
using System;

namespace lainxi8
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("xxxxxxxxxxxxxxx");
            Console.WriteLine ("1.T恤"+"   "+"2.帽子");
            Console.WriteLine ("xxxxxxxxxxxxxxx");
            Console.WriteLine ("请开始你的购物 (y/n)");
            string number=Console.ReadLine();
            while(number="y")
            {
               
                Console.WriteLine ("请输入商品编号:");
                int num = int.Parse (Console.ReadLine ());
                Console.WriteLine ("请输入你的购物数量:");
                 int num1 = int.Parse (Console.ReadLine ());
                if(num==1)
                {
                    Console.WriteLine ("T恤"+" "+"$240"+"  "+"数量:"+" "+num1+"  "+"合计"+num1*240);
                }
                else
                {
                    Console.WriteLine ("帽子"+" "+"$100"+"  "+"数量"+" "+num1+" "+"合计"+num1*100);
                }
                Console.WriteLine ("是否继续购买(y/n)");
                string nu=Console.ReadLine();
                }
                int a = (num1 * 240 + num1 * 100);
                Console.WriteLine ("应付今额:"+a);
                Console.WriteLine ("给钱:");
                int b = int.Parse (Console.ReadLine ());
                if(b>a)
                {
                    Console.WriteLine ("找钱:"+(b-a)
                    );
                }
                else
                {
                    Console.WriteLine ("你给的钱不够啊!!");
                }

                }

        }
    }
}


[此贴子已经被作者于2018-11-14 19:19编辑过]

搜索更多相关主题的帖子: 调用 while Console WriteLine int 
2018-11-14 18:45
徐夏语
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-11-14
得分:0 
求结果

大神求解一下
2018-11-14 18:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-491264-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.296426 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved