大佬教程收集整理的这篇文章主要介绍了介绍类C#for循环问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
class Program { static void Main(String[] args) { Console.WriteLine("Enter number of customers: "); var numCust = Convert.ToInt32(Console.ReadLine()); int lunchCombo = 0; decimal @R_22_10586@l = 0; Console.WriteLine("Enter lunch combo purchased"); lunchCombo = Convert.ToInt32(Console.ReadLine()); for ( int i = 1; i < numCust; i++ ) switch (lunchCombo) { case 1: Console.WriteLine("Enter lunch combo purchased"); lunchCombo = Convert.ToInt32(Console.ReadLine()); @R_22_10586@l = @R_22_10586@l + 4.25M; break; case 2: Console.WriteLine("Enter lunch combo purchased"); lunchCombo = Convert.ToInt32(Console.ReadLine()); @R_22_10586@l = @R_22_10586@l + 5.75M; break; case 3: Console.WriteLine("Enter lunch combo purchased"); lunchCombo = Convert.ToInt32(Console.ReadLine()); @R_22_10586@l = @R_22_10586@l + 5.25M; break; case 4: Console.WriteLine("Enter lunch combo purchased"); lunchCombo = Convert.ToInt32(Console.ReadLine()); @R_22_10586@l = @R_22_10586@l + 3.75M; break; default: Console.WriteLine("Invalid input"); break; } Console.WriteLine("Your @R_22_10586@l is {0}",@R_22_10586@l); Console.ReadKey(); } }
>餐厅有4个午餐组合供客户选择:
组合1:带炸鸡的炸鸡[价格:4.25]
组合2:土豆泥烤牛肉[价格:5.75]
组合3:鱼和薯条[价格:5.25]
组合4:汤和沙拉[价格:3.75]
写一个程序,询问客户订购哪种午餐组合.使用switch语句确定并显示客户需要支付的金额.如果客户订购了菜单上没有的内容,则显示“无效输入”.不要使用任何if … else语句.
>展开计划3以计算一组客户应付的总金额.该程序首先询问该组中的客户数量.然后它使用循环逐个接受订单.如果客户订购的菜单不在菜单上,请忽略该订单并转到下一位客户.使用组中的客户数来确定循环执行的次数.不要让用户输入特殊值(如-1)来停止循环.计算并显示该组需要支付的总金额.
var @R_22_10586@l = 0; var numCust = "How Many Customers?" for (int i = 0; i < numCust; i++){ var combo = "what Combo do you want?" switch (combo){ case 1: @R_22_10586@l += 4.25; break; case 2: @R_22_10586@l += 5.25; break; case 4: @R_22_10586@l += 5.75; break; } } write("The @R_22_10586@l is: " + @R_22_10586@l);
以上是大佬教程为你收集整理的介绍类C#for循环问题全部内容,希望文章能够帮你解决介绍类C#for循环问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。