Sorry this answer is so late compared to the question, but I just saw the question.
You include <iostream> in the program to include the classes for input output stream.
This provides you with the ability to call cin and cout.
cin is console input and allows the program to get keyboard input.
cout displays the text to the screen.
In basic C you included stdio.h and to write to the screen was done with a printf () command.
You can modify this program to keep asking for the number until the user guess the proper number, and provide an exit as follows:
---------------------------------------------------------
#include <iostream>
using namespace std;
int main()
{
int x, found = 0;
while (!found) // we will loop until found is set to true
{
cout << "Guess what number I am thinking of between 1 and 10: Enter 0 to exit";
cin >> x;
cin.ignore();
if (x < 1 || x > 10)
cout << "That is an invalid entry !!";
else if (x == 0)
{
cout << "Exiting";
found = 1;
}
else if (x == 7)
cout << "Very good you must be psychic.\n";
else
cout << "Sorry you guessed wrong.\n";
}
}
------------------------------------------------------------------------
By the way I have been a software engineer for 30 years and have been coding in C and C++ for 27 years