C++找零钱并界面设计
时间: 2023-11-14 11:12:51 浏览: 89
这里给出一个简单的 C++ 找零钱程序,并附带基本的命令行界面设计。
```c++
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int amount, twenties, tens, fives, ones;
cout << "Enter the amount of change: ";
cin >> amount;
twenties = amount / 20;
amount %= 20;
tens = amount / 10;
amount %= 10;
fives = amount / 5;
amount %= 5;
ones = amount;
cout << "\nChange breakdown: " << endl;
cout << setw(10) << left << "Twenties:" << twenties << endl;
cout << setw(10) << left << "Tens:" << tens << endl;
cout << setw(10) << left << "Fives:" << fives << endl;
cout << setw(10) << left << "Ones:" << ones << endl;
return 0;
}
```
以上代码通过输入需要找的钱数,计算出所需的各种面额的钞票数量,并输出结果。
接下来,我们可以通过简单的命令行界面设计来让程序更加友好。下面是一个示例:
```c++
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int amount, twenties, tens, fives, ones;
cout << "=====================================" << endl;
cout << "| Change Calculator |" << endl;
cout << "=====================================" << endl;
cout << "Enter the amount of change: $";
cin >> amount;
twenties = amount / 20;
amount %= 20;
tens = amount / 10;
amount %= 10;
fives = amount / 5;
amount %= 5;
ones = amount;
cout << "\nChange breakdown: " << endl;
cout << "-------------------------------------" << endl;
cout << setw(10) << left << "Twenties:" << twenties << endl;
cout << setw(10) << left << "Tens:" << tens << endl;
cout << setw(10) << left << "Fives:" << fives << endl;
cout << setw(10) << left << "Ones:" << ones << endl;
cout << "-------------------------------------" << endl;
return 0;
}
```
在这个示例中,我们使用了一些 ASCII 艺术来美化界面。同时,我们也加入了分割线,使得输出更加清晰易读。
这只是一个简单的命令行界面示例,你可以通过更改输出文本、添加更多分割线或者使用更加复杂的 ASCII 艺术来设计出更加漂亮的界面。
阅读全文