This should give yo an idea of what your program is doing. With my VS IDE I had problems getting the program. It might work for you. If it does either you have an old compiler or you may need to change some settings.
The comments in the program show what I received when I tried to compile the program. Line 3 is what I had to use just to get the program to compile. Then it crashed when the program ran.
#include <iostream>
//#pragma warning(disable : 4700) // <--- You may or may not need this line.
int main ()
{
int x, y, c, n;
// Error C4700 uninitialized local variable 'n'
// Same error for the other variables.
std::cout << "\n x = " << x << ", y = " << y << ", c = " << c << ", n = " << n << std::endl;
// What I finally got it to produce.
// x = -858993460, y = -858993460, c = -858993460, n = -858993460
std::cout << "Enter a value for x: ";
std::cin >> x;
n = 0;
while (x != 0)
{
x = y; c = 0;
while (y>0)
{
if (y % 10>c) c = y % 10; y = y / 10;
}
n = n * 10 + c; std::cin >> x;
}
std::cout << "n=" << n << std::endl;
return 0;
}
What this means is that you need to initialize your variables. The simplest way would be:int x{}, y{}, c{}, n{}; . The empty {}s will set the numeric variables to zero.
It is always a good practice to initialize your variables when defined. This program is a good example of what happens when you do not initialize your variables.