求各位大老来解答一下

问题如下

img

为什么在调试的时候没有出现计算结果,难道是我的代码出错了?

#include
using namespace std;
int main()
{
    int a = 0;//个位
    int b = 0;//十位
    int c = 0;//百位
    int num = 100;
    do {
        
        a = num % 10;
        b = num / 10 % 10;
        c = num / 100;
        a++;
        b++;
        c++;
        if ( a * a * a + b * b * b + c * c * c==num)
        {
            cout <<"水仙花数字为 "<< num <num++;
        
    } while (num > 1000);
    
    system("pause");
    
    return 0;
}

img

while (num < 1000)
另外你a,b,c都加1是要干啥啊???删掉

#include<iostream>
using namespace std;
int main()
{
    int a = 0;//个位
    int b = 0;//十位
    int c = 0;//百位
    int num = 100;
    do {
        
        a = num % 10;
        b = num / 10 % 10;
        c = num / 100;
       
        if ( a * a * a + b * b * b + c * c * c==num)
        {
            cout <<"水仙花数字为 "<< num <<endl;
        }
        num++;
        
    } while (num < 1000);
    
    system("pause");
    
    return 0;
}

  • 先看截图

img

  • 修改如下:
#include<iostream>
using namespace std;
int main()
{
    int a = 0;//个位
    int b = 0;//十位
    int c = 0;//百位
    int num = 100;
    do {
        
        a = num % 10;
        b = num / 10 % 10;
        c = num / 100;
        // a++;
        // b++;
        // c++;
        //printf("%d %d %d %d", a, b, c, num);
        if ( a * a * a + b * b * b + c * c * c==num)
        {
            cout <<"水仙花数字为 "<< num <<endl;
        }
        num++;
        
    } while (num < 1000);
    
    system("pause");
    
    return 0;
}