So something isn't working right in this code,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
cout << "Enter a 3 digit number, whose first digit is greater than its last\n";
cin >> number1;
cout << "The number you entered is:" << number1<<endl;
while (number1 > 0)
{
number2 = number2 * 10 + (number1 % 10);
number1 = number1 / 10;
cout << "The reverse of your input is " << number2<<endl;
}
number3=(number1-number2);
cout << "Subtraction of the reversal from the original number is " << number3<<endl;
{
number4 = number4 * 10 + (number1 % 10);
number3 = number3 / 10;
cout << "The reverse of the resulting number is " << number4<<endl;
}
number5 = (number3 + number4);
cout << "Addition of the number to the un-reversed form is " << number5 << " our magic number" << endl;
|
It should be taking a number, reversing it, subtracting the reversal from the original, reversing it again and then adding the number to the un-reversed form. Like this 901 109 901-109=792 297+792=1089.
When I run it, the results look like this
Enter a 3 digit number, whose first digit is greater than its last
801
The number you entered is:801
The reverse of your input is 1
The reverse of your input is 10
The reverse of your input is 108
Subtraction of the reversal from the original number is -108
The reverse of the resulting number is 0
Addition of the number to the un-reversed form is -10 our magic number
Press any key to continue . . .