嵌套循环
假设有5个专卖店促销,每个专卖店每人限购3件衣服,可以随时选择离开,离店时要结账。编写程序简单模拟这个购物的流程。这里学习和练习使用for循环实现嵌套循环using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sale
{
class Program
{
static void Main(string[] args)
{
int count= 0;
int i, j;
String choice;
for (i = 0; i < 5; i++)
{
Console.WriteLine("欢迎来到第{0}家专卖店",i+1);
for(j=0;j<3;j++)
{
Console.WriteLine("您要离开吗? yes/no");
choice = Console.ReadLine();
if(choice=="yes")
{
break;
}
Console.WriteLine("您选购了一件衣服");
count++;
}
//结账
Console.WriteLine("您一共买了{0}件",count);
}
Console.ReadKey();
}
}
}
C#嵌套循环 嵌套循环 假设有5个专卖店促销,每个专卖店每人限购3件衣服,可以随时选择离开,离店时要结账。编写程序简单模拟这个购物的流程。这里学习和练习使用for循环实现嵌套循环
猜你喜欢
转载自blog.csdn.net/HCY008042/article/details/104659493
今日推荐
周排行