【发布时间】:2015-02-21 13:13:02
【问题描述】:
我来自 C++ 背景。我最近编写了一个程序,它提供了有关特定卢比的音符数量的信息。当它要求特定数量时需要。 以下是我的代码:
#include <iostream>
using std::cout;
using std::cin;
int main()
{
int amount,notes,choice;
cout<<"Enter the amount: ";
cin>>amount;
cout<<"Enter the value of note from which you want to start: ";
cin>>choice;
switch(choice)
{
case 100:
notes=amount/100;
cout<<"no of 100 rupees notes = "<<notes<<'\n';
amount=amount%100;
case 50:
notes=amount/50;
cout<<"no of 50 rupees notes = "<<notes<<'\n';
amount=amount%50;
case 20:
notes=amount/20;
cout<<"no of 20 rupees notes = "<<notes<<'\n';
amount=amount%20;
case 10:
notes=amount/10;
cout<<"no of 10 rupees notes = "<<notes<<'\n';
amount=amount%10;
case 5:
notes=amount/5;
cout<<"no of 5 rupees notes = "<<notes<<'\n';
amount=amount%5;
case 2:
notes=amount/2;
cout<<"no of 2 rupees notes = "<<notes<<'\n';
amount=amount%2;
case 1:
notes=amount/1;
cout<<"no of 1 rupees notes = "<<notes<<'\n';
break;
default:
cout<<"Enter only valid values";
}
return 0;
}
现在我的问题是如何用 C# 编写这个程序?在 C# 中没有隐式的失败案例,但在这个程序中,需要隐式的失败案例。那么我可以通过哪些方式在 C# 中执行此程序? 请帮帮我。
【问题讨论】:
-
您是否受限于在解决方案中使用
switch语句? -
失败是我在 30 多年的 IT 行业中见过的最愚蠢的事情之一,也是糟糕的编程风格的明确标志,imnsho
标签: c# c++ switch-statement