小编Som*_*g17的帖子

为什么这个程序本来要返回美元、25 美分和 10 美分,但数学却没有正确地进行?

我正在尝试编写一个程序,该程序将返回特定整数美分的零钱。例如 92 美分将返回:0 美元、3 个 25 美分、1 毛钱、1 镍币和 2 便士。

这是我到目前为止的代码:

#include <iostream>

using namespace std;

int main() {
    
    // 1. ask user to enter an integer: total cents
    cout << "Hi! Enter an integer representing the total number of cents pls: " << endl;
    
    int user_num{};
    
    // 2. save in std cin
    cin >> user_num;
    
    // 3. check dollars
    int dollars{};
    int add_to_dollars{};
    
    if ( user_num >= 100 ) {             // eg. user_num is 240 
        // calculate amount …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm math

-1
推荐指数
1
解决办法
131
查看次数

标签 统计

algorithm ×1

c++ ×1

math ×1