When i run my game the life mechanism is supposed to appear only once at each "round" but what it do is:
Enter a number other than 0: 7
Enter a number other than 1: 8
you have 9 lifes left
you have 8 lifes left
you have 7 lifes left
...
you have 1 lifes left
Enter a number other than 2: 6
Can someone fix it to be like:
Enter a number other than 0: 7
You have 9 lifes left
Enter a number other than 1: 4
you have 8 lifes left
...
Until the GAME OVER.
here is the code:
#include <iostream>
usingnamespace std;
int main ()
{
int n, d, x;
cout << "Enter a number other than 0: ";
cin >> d;
for (n=1;n!=0;n++)
{
if (d!=0)
{
cout << "Enter a number other than " << n << ": ";
cin >> d;
getchar ();
if (n==d)
{
cout << "Other than " << n << "!";
goto exit;
getchar();
}
}
for (x=9; x>0; x--)
{
cout << "You have " << x << " lives left\n";
if (x==0)
{
cout << "GAME OVER";
getchar ();
goto exit;
}
}
}
exit:
getchar ();
return 0;
}