gpt4 book ai didi

c++ - 除法对负数停止工作

转载 作者:太空宇宙 更新时间:2023-11-04 15:24:07 24 4
gpt4 key购买 nike

<分区>

我让它显示红利,这样人们就可以轻松破译代码。它工作过一次,但后来我不知道我做了什么让它停止工作。它非常适合正整数。它应该显示与用户输入关联的数字。

#include <iostream>                                        // Necessary header
using namespace std;

int main()
{
signed int Input, Divisor, Dividend, MSD;

cout << "Input:";
cin >> Input;

Divisor = 1;
Dividend = Input;
if (Input < 0)
{
Dividend *= -1;
cout << "minus ";
}

cout << Dividend;
while (Dividend > 9)
{
Divisor = Divisor * 10;
Dividend = Dividend / 10;
}

while (Divisor != 0)
{
MSD = Input / Divisor;
switch (MSD)
{
case 0:
cout << "zero ";
break;
case 1:
cout << "one ";
break;
case 2:
cout << "two ";
break;
case 3:
cout << "three ";
break;
case 4:
cout << "four ";
break;
case 5:
cout << "five ";
break;
case 6:
cout << "six ";
break;
case 7:
cout << "seven ";
break;
case 8:
cout << "eight ";
break;
case 9:
cout << "nine ";
break;
}
Input = Input - (MSD * Divisor);
Divisor /= 10;
}
return 0;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com