Hello, I created a simple number guessing game which thinks of a secret number from 1 to 100. It tells the user if his guess is high or low and finally stops after the secret number is equal to the user's input, it also notes down the number of tries. It then asks if the user wants to try again, but whenever it runs to play again, the number of tries add up to the previous result. What am I missing? Also, the setw() function doesn't seem to work. Thanks!
#include <cstdlib> //directive for rand() function
#include <time.h> // directive for random pick of number
#include <iomanip>
#include <iostream>
using namespace std;
int main(){
srand(time(0)); //changes the secret number
int number;
number = rand() % 100 + 1; //range of secret number 1-100
int guess;
int tries = 1;
int play = 1;
pick:
cout << setw(5) << "\nWelcome to the Guess the number game! " ;
cout << setw(5) << "\nI'm thinking of a secret number from 1 to 100 " ;
cout << setw(5) << "\nGuess it!\n\n" ;
do { //loops until guess is equal to secret number
cout << "\nEnter your estimate: ";
cin >> guess;
if (guess < number){
cout << "Higher!" << endl;
tries = tries + 1;}
else if (guess > number){
cout << "Lower!" << endl;
tries = tries + 1;}
else
cout << "Your guess is right!" << endl;
} while (guess != number);
cout << "\n\nYou tried "<<tries<<" times " ;
char g;
cout << "\nTry Again? (y for yes or n for no): ";
cin >> g;
if(g !='n'){
srand(time(0));
play = play + 1;
system("cls");
goto pick;}
else {
cout << "\nNumber of game plays is "<<play<<"\n\n" ;}
system("PAUSE");
return 0;}