
Originally Posted by
sIMson
Downloaded Dev-C++, compiled the code i had, it works perfectly as with the other program only that when i win/lose the game it instantly close :S
--- Update ---
Updated the code, now use self explanatory variables.
Updated the game, now it doesn't instantly close after the match finish, it has rules shown up, it asks if you want to repeat the match (only availiable to repeat with the same language), if you set up an unkown language it instantly switchs to english and asks if you want to play in english or leave the game.
@sIMson could you explain how would i make AdminVariable randomized by the program?
As far as i understand i would need to add: #include<stdlib.h>
and replace the player1 part by: rand(AdminVariable);
The problem is that AdminVariable would be able not to be within the values i want (1 and 1000), how would i make it randomize between 1 and 1000 (1 and 1000 included)?
Thx for the help 
The code right now is:
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int AdminVariable;
int Language;
int TryLeft;
int Guess;
int CurrentTry;
int Repeat;
Repeat=1;
cout<<"Type your language take in consideration:"<<endl;
cout<<"We only support Portuguese, Spanish and English"<<endl;
cout<<"Spanish = 1, English = 2, Portuguese = 3"<<endl;
cin>>Language;
while (Repeat == 1) {
switch (int(Language)) {
case 1:
CurrentTry=1;
TryLeft=10;
cout<<""<<endl;
cout<<"Empezando el juego en Español"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Reglas:"<<endl;
cout<<"1: Jugador1 elige un numero entre 1 y 1000"<<endl;
cout<<"2: Jugador2 intenta advinar ese numero, teniendo 10 intentos"<<endl;
cout<<"3: Cada vez que el jugador2 falla, se le da una pista"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Jugador 1"<<endl;
cout<<"Elige un numero entre 1 y 1000."<<endl;
cin>>AdminVariable;
if (AdminVariable>1000 || AdminVariable<1) {
cout<<"Valor invalido, sigue las reglas."<<endl;
} else {
cout<<"Jugador 2"<<endl;
cout<<"Intenta advinar el numero, desde 1 hasta 1000. Cuidado, tienes "<<TryLeft<<" intentos."<<endl;
cin>>Guess;
if (Guess<AdminVariable || Guess>AdminVariable) {
while ((Guess<AdminVariable || Guess>AdminVariable) && TryLeft>0) {
CurrentTry=CurrentTry+1;
TryLeft=TryLeft-1;
if (TryLeft>0) {
if (Guess<AdminVariable) {
cout<<"Has fallado, el numero es mayor. Tienes mas "<<TryLeft<<" intentos."<<endl;
cin>>Guess;
} else {
cout<<"Has fallado, el numero es mas chico. Tienes mas "<<TryLeft<<" intentos."<<endl;
cin>>Guess;
}
} else {
cout<<"Has Perdido! El numero correcto era: "<<AdminVariable<<endl;
cout<<"Quieres repetir? (Si = 1, No = 2)"<<endl;
cin>>Repeat;
}
}
if (TryLeft>0) {
cout<<"Has Ganado! Has acertado a la "<<CurrentTry<<"ª!"<<endl;
cout<<"Quieres repetir? (Si = 1, No = 2)"<<endl;
cin>>Repeat;
}
} else {
if (TryLeft>0) {
cout<<"Has Ganado! Has acertado a la "<<CurrentTry<<"ª, impresionante!"<<endl;
cout<<"Quieres repetir? (Si = 1, No = 2)"<<endl;
cin>>Repeat;
}
}
}
break;
case 2:
CurrentTry=1;
TryLeft=10;
cout<<""<<endl;
cout<<"Starting the game in English"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Rules:"<<endl;
cout<<"1: Player1 choise a number between 1 and 1000"<<endl;
cout<<"2: Player2 tries to guess the number, having 10 tries"<<endl;
cout<<"3: Each time player2 fails it's given a tip"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Player 1"<<endl;
cout<<"Choise a number from 1 to 1000."<<endl;
cin>>AdminVariable;
if (AdminVariable>1000 || AdminVariable<1) {
cout<<"Invalid number, follow the rules"<<endl;
} else {
cout<<"________________________________________________________________________________"<<endl;
cout<<"Player 2"<<endl;
cout<<"Try to guess the number. Be carefull, you have "<<TryLeft<<" tries."<<endl;
cin>>Guess;
if (Guess<AdminVariable || Guess>AdminVariable) {
while ((Guess<AdminVariable || Guess>AdminVariable) && TryLeft>0) {
CurrentTry=CurrentTry+1;
TryLeft=TryLeft-1;
if (Guess>0) {
if (Guess<AdminVariable) {
cout<<"You failed, the number is bigger. You have "<<TryLeft<<" tries left."<<endl;
cin>>Guess;
} else {
cout<<"You failed, the number is smaller, You have "<<TryLeft<<" tries left."<<endl;
cin>>Guess;
}
} else {
cout<<"You Lost! The correct number was: "<<AdminVariable<<endl;
cout<<"Want to repite? (Yes = 1, No = 2)"<<endl;
cin>>Repeat;
}
}
if (CurrentTry==2) {
cout<<"You won on the "<<CurrentTry<<"nd try!"<<endl;
cout<<"Want to repite? (Yes = 1, No = 2)"<<endl;
cin>>Repeat;
} else {
if (CurrentTry==3) {
cout<<"You won on the "<<CurrentTry<<"rd try!"<<endl;
cout<<"Want to repite? (Yes = 1, No = 2)"<<endl;
cin>>Repeat;
} else {
cout<<"You won on the "<<CurrentTry<<"th try!"<<endl;
cout<<"Want to repite? (Yes = 1, No = 2)"<<endl;
cin>>Repeat;
}
}
} else {
if (TryLeft>0) {
cout<<"You won on the "<<CurrentTry<<"st try, impressive!"<<endl;
cout<<"Want to repite? (Yes = 1, No = 2)"<<endl;
cin>>Repeat;
}
}
}
break;
case 3:
CurrentTry=1;
TryLeft=10;
cout<<""<<endl;
cout<<"Começando o jogo em Portuguese"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Regras:"<<endl;
cout<<"1: Jogador1 escolhe un numero entre 1 y 1000"<<endl;
cout<<"2: Jogador2 tenta advinhar eese numero, tendo 10 tentativas"<<endl;
cout<<"3: Cada vez que o jugador2 falha, da-se uma pista"<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Jogador 1"<<endl;
cout<<"Escolhe um numero desde 1 até 1000."<<endl;
cin>>AdminVariable;
if (AdminVariable>1000 || AdminVariable<1) {
cout<<"Valor invalido, segue as regras."<<endl;
} else {
cout<<"Jogador 2"<<endl;
cout<<"Tenta advinhar o numero, desde 1 até 1000. Cuidado, tens "<<TryLeft<<" tentativas."<<endl;
cin>>Guess;
if (Guess<AdminVariable || Guess>AdminVariable) {
while ((Guess<AdminVariable || Guess>AdminVariable) && TryLeft>0) {
CurrentTry=CurrentTry+1;
TryLeft=TryLeft-1;
if (TryLeft>0) {
if (Guess<AdminVariable) {
cout<<"Falhaste, o numero é maior. Tens mais "<<TryLeft<<" tentativas."<<endl;
cin>>Guess;
} else {
cout<<"Falhaste, o numero é mais pequeno. Tens mais "<<TryLeft<<" tentativas."<<endl;
cin>>Guess;
}
} else {
cout<<"Perdeste! O numero correcto era: "<<AdminVariable<<endl;
cout<<"Queres repetir?? (Sim = 1, Não = 2)"<<endl;
cin>>Repeat;
}
}
if (TryLeft>0) {
cout<<"Ganhaste! Acertaste à "<<CurrentTry<<"ª!"<<endl;
cout<<"Queres repetir?? (Sim = 1, Não = 2)"<<endl;
cin>>Repeat;
}
} else {
if (TryLeft>0) {
cout<<"Acertaste à "<<CurrentTry<<"ª, impresionante!"<<endl;
cout<<"Queres repetir?? (Sim = 1, Não = 2)"<<endl;
cin>>Repeat;
}
}
}
break;
default:
Language=2;
cout<<"Language Not Supported!"<<endl;
cout<<"If you want play in English press yes(1) or no(2)."<<endl;
cin>>Repeat;
break;
}
}
return 0;
}