运行数学函数后,如何不将其显示在屏幕上
After running a mathematical function, how do I not display it to the screen?
对于糟糕的标题,我提前道歉,很难找到几个词来有效地概括我的问题。我必须做一个编程项目来制作收银机。找到物品的总金额后,我必须输入一个零钱值,并用二十、十、五、单、四分之一、一角钱、镍币和便士找零。我已经完成了计算钞票和硬币变化的编程,但我的教授希望我们如果没有归还任何钞票或硬币,就不要包括纸币或硬币。
这是我到目前为止的代码-
void find_change(){
double change_given, updated_price, coin_price;
//item_price_total = 318.32; keep this in here for testing purposes
//change_given = 405.23; ' '
int twenties,
tens,
fives,
singles,
quarters,
dimes,
nickels,
pennies;
//finds the change in bills
do{
cout << "How much change is given? " << endl;
while(!(cin >> change_given)){ //tests to make sure value entered can be used
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), 'n');
cout << "Invalid input. Try again: ";
}
if(change_given < item_price_total){
cout << "You did not give the machine enough money" << endl;
}
}while(change_given < item_price_total);
updated_price =change_given-item_price_total;
cout << "The total price is: " << item_price_total << endl;
cout << "The change given is: " << change_given << endl;
cout << "The change back will be: " << updated_price << endl;
twenties = updated_price / 20;
cout << "Twenties: " << twenties << endl;
updated_price = updated_price -(twenties *20);
tens = updated_price/10;
cout << "Tens: " << tens << endl;
updated_price = updated_price - (tens*10);
fives = updated_price/5;
cout << "Fives: " << fives << endl;
updated_price = updated_price - (fives*5);
singles = updated_price/1;
cout << "Singles: " << singles << endl;
updated_price = updated_price - (singles*1);
//this part finds the coins left
coin_price = updated_price * 100;
//finds the change in coins
quarters = coin_price/25;
cout << "Quarters: " << quarters << endl;
coin_price = coin_price - (quarters*25);
dimes = coin_price/10;
cout << "Dimes: " << dimes << endl;
coin_price = coin_price - (dimes*10);
nickels = coin_price/5;
cout << "Nickels: " << nickels << endl;
coin_price = coin_price - (nickels*5);
pennies = coin_price/1;
cout << "Pennies: " << pennies << endl;
coin_price = coin_price - (pennies*1);
}
当我将其全部粘贴到此处时,我为它的格式错误表示歉意。该功能本身运行良好,当返回的更改不包括某个钞票或硬币时,我不知道如何不包括它。谢谢!
添加硬币/纸币价值的测试。
#include <iostream>
#include <vector>
using namespace std;
struct Currency {
const char * name;
int value;
};
Currency values[] = {
{"Twenty", 2000},
{"Tens", 10000},
{"Dimes", 10},
{"Pennies",1}
};
int main() {
int change = 101;
for(auto& i: values){
int units = change /i.value;
if(units)// test that there is some change with these coins/notes
std::cout << i.name << units << endl;
change -= units*i.value;
}
return 0;
}
相关文章:
- Winapi:屏幕截图未显示在窗口中
- 如何在快板的屏幕中显示子位图的绘制?
- SFML 中的字体.信息不显示在屏幕上.显示的不是信息,而是点
- 如何使用 openGL 在屏幕上显示加载的纹理
- 如何使用方法覆盖在输出屏幕上显示堆栈整数值
- 如何使用TouchGFX在LCD屏幕上显示ADC值
- 为什么屏幕上显示了一半的三角形
- 如何在屏幕上显示对象列表?
- C++列出屏幕以在第二台显示器中显示图像
- 显示和隐藏Windows 10屏幕键盘(osk.exe)时遇到问题
- 将25个甚至整数存储到一个名为intlist的整数阵列中,然后在屏幕上显示数组,并在屏幕上显示名为fivintegers
- QML强制窗口将在第一个屏幕上显示
- 如何使用OpenGL在屏幕上显示三角形
- 从文本文件中读取行并显示在屏幕上
- 我的程序没有将字符显示在屏幕上
- 在屏幕上显示矢量
- 在同一屏幕上显示两个不同的对象
- 屏幕显示脚本中'.'令牌之前的预期非限定 id
- C / SFML:使用两个递归调用在屏幕上打印凸形形状仅显示第一个递归调用中的形状,而不是第二个
- 如果我使用的是迭代器,为什么在c++中没有屏幕显示呢