The output you show in the image file is NOT from the C++ code
that you posted. There can be various reasons why this happens.
Two of the most common are:
(1) The code you are TRYING to build and run is NOT in a source
file that is part of a Project in the Solution which is open
in the IDE. You can't just open a C++ source file in the IDE and
think that it will get built and executed. It won't, unless
it is specified in the Solution/Project settings.
(2) When you have changed the code in a .cpp file that is
part of an open Project and there are errors in the Build
that prevent a successful build (compile and link), the IDE
may give you the choice to execute the last successfully
built .exe for that Project. If you choose to run that
then the output will reflect what was in the old version
of the .cpp source code.
As a general rule - especially for beginners - I recommend
that you do NOT use Run and depend on an implicit Build
whenever you change code. That has a tendency to "hide" the
results of the Build process as the Output Window will
show the result of the failed attempt to execute the
I recommend that you always do an explicit Build or Rebuild
first. Only after there are no errors from the Build should
you try to Run the program.
To avoid seeing results from an earlier version of the
code, it's a good practice to do an explicit Clean of
the Solution before doing a Build/Rebuild/Run. Normally
that isn't a necessary explicit step, but when you are
seeing "leftover" results from earlier builds it can
help eliminate the clutter and reduce confusion.