Please do avoid global variables...I have just tweaked your program....



#include <iostream>

using namespace std;