I made this Guess the number game for a class assignment based on this code C++ Random number guessing game
I first tried to make it with the "goto" function and it worked perfectly, but my teacher says I need to make it using "while".
The problem is that the program keeps closing after the "Troppo basso!" and "Troppo alto!" messages appear, can somebody tell me why?
#include <iostream>
using namespace std;
int main()
{
int Nuovogioco = 0;
if (Nuovogioco == 0)
{
srand(time(0));
int Numero = rand() % 100 + 1;
int prova;
int Variabile;
int Periodo = 0;
Nuovogioco++;
{
while (Periodo <1 )
{
cout << "A che numero sto pensando da 1 a 100? ";
cout <<endl;
cout << "Se vuoi uscire digita e quando vuoi!";
cout <<endl;
cout << "Inserisci un numero: ";
Periodo++;
}
while (Periodo > 0)
{
cin >> prova;
if (prova > Numero)
{
cout << "Troppo alto!" <<endl;
Periodo--;
}
if (prova < Numero)
{
cout << "Troppo basso!" <<endl;
Periodo--;
}
if (prova == Numero)
{
cout << "Hai vinto! Se vuoi rigiocare digita 1, altrimenti digita 2!";
cin >> Variabile;
{
if (Variabile == 1)
{
Variabile--;
Nuovogioco--;
}
if (Variabile == 2)
{
cout << "Byebye! ";
system ("pause");
}
}
}
}
}
}
}