Quote:
How to print the output 8
Technically, this is what you ask for:
cout << 8;
But I am not sure it answer your problem.
My guess:
Yes, ultimately, your program don't "print the 8", but is it the problem ? I guess it is not.
What should do your program:
1) get the data
2) apply an algorithm to the data
3) print the answer to the algorithm, and Yes the expected answer is 8
As a programmer your job is also to track down the origin of bugs, and the debugger is an invaluable tool for this.
1) you need to make sure the entered data is correctly stored in variables, the debugger will help you to make sure of this.
2) you need to make sure your algorithm is doing what it should, here again use the debugger.
3) you need to make sure the result of the algorithm is printed correctly, here again use the debugger.
If the problem is in the algorithm, you know how the algorithm have to process the data, with the debugger, you will be able to the step by step what your program is really doing, by comparing with what it should do, the bug is when it is not a match.
don't forget to inspect variables on every step.
-----
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.
The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[
^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.