将数字划分为直到满足条件= 0



我必须在程序中输入一个值,并将其除以4,直到达到数字0。但是当我运行它时,它不会在0中停止,它会继续重复重复0永远。代码怎么了?

#include <iostream>
using namespace std;
int main(){
    double input;
    cout << "Enter an Integer: ";
    cin >> input;
    cout << input << "/ 4 ";
    do
    {
        input = input / 4;
        if (input >= 0)
            cout <<" = "<< input << endl;
        cout <<input << " /4";
    }
    while ((input >= 0) || (input != 0));
    return 0;
}

这是我的三分钱。:(

#include <iostream>
int main() 
{
    const long long int DIVISOR = 4;
    while ( true )
    {
        std::cout << "Enter an Integer (0 - Exit): ";
        long long int n;
        if ( not ( std::cin >> n ) or ( n == 0 ) ) break;
        std::cout << std::endl;
        do
        {
            std::cout << n << " / " << DIVISOR;
            n /= DIVISOR;
            std::cout << " = " << n << std::endl;
        } while ( n );
        std::cout << std::endl;
    }
    return 0;
}

程序输出可能看起来像

Enter an Integer (0 - Exit): 1000
1000 / 4 = 250
250 / 4 = 62
62 / 4 = 15
15 / 4 = 3
3 / 4 = 0
Enter an Integer (0 - Exit): 0

最新更新