Joc C++ "Ghiceste Numarul Secret" 2018

» phpBB 3.0.x, MyBB, HTML, CSS, PHP & MySQL .htaccess .etc.
Post Reply
User avatar
BGY95
Membru
Posts: 3
Joined: 27 Oct 2018, 10:06
Nivel cunoştinţe IT: 5

27 Oct 2018, 10:23

Sper sa va placa. Eu folosesc DEV C++ (Nu l-am testat pe Microsoft Visual).

#include <iostream>
#define clear_screen system("cls")
#define sa_se_faca_lumina system("color 5A")

using namespace std;
int vector[50];
void Citire_n_secret(int &n_secret)
{
cout << "Introdu numarul secret: "; cin >> n_secret;
}
void Welcome()
{
cout << " Bine ai venit!\n Jocul se numeste GHICESTE NUMARUL SECRET"<<endl;
}

int Citire_incercare(int &n, int i, int vector[])
{
cin >> n;
vector[i] = n;
return n;
}
void afiseaza_vector(int i, int vector[])
{
for (int k=0;k<i;k++)
cout << vector[k] << " ";
}
void mesaje (int greseli)
{
if (greseli <= 3) cout << "FANTASTIC! Un scor foarte bun!";
if (greseli > 3 && greseli < 7) cout << "Se putea si mai bine...";
if (greseli >=7 && greseli <= 10) cout << "Hmmmm..... Nu e prea bine!";
if (greseli >10 && greseli <=15) cout << "Ai facut prea multe greseli!";
if (greseli >15) cout << "Foarte multe greseli!";
}
void dasd(int n, int n_secret, int greseli, int vector[])
{
clear_screen;
Welcome();
char lit, lit2;
int ad, admin = {1234};
cout << "Esti admin? D/d = afirmativ | Alta tasta pentru negativ" << endl;
cin >> lit;
if (lit=='D' || lit=='d')
{
cout << "Ok, sa vedem..." << endl;
cout << "Introdu parola de admin:" << endl;
cin >> ad;
if(ad==admin)
{
cout << "Esti admin!" << endl;
cout << "Numarul secret este: " << n_secret << endl;
cout << "Doresti sa inchizi programul? d/D = DA, n/N = NU" << endl;
cin >> lit2;
if(lit2=='d' || lit2=='D') exit(0);
if(lit2=='n'|| lit2=='N') cout << "Programul continua." << endl;
else cout << "Se ingora" << endl;
}
else cout << "Parola este incorecta! Nu esti admin!" << endl;
}
else
{
clear_screen;
cout << "Programul continua." << endl;
}
int i =0;
int limita_stanga, limita_dreapta;
cout << "Ghiceste numarul secret: ";
Citire_incercare(n,i,vector);
i++;
if (n==n_secret)
{
cout << "Felicitari! Ai ghicit numarul secret din prima incercare!" <<endl;
cout << "E-MAIL: butnaru.gheorghita@yahoo.com\n";
exit(0);
}
bool test = false, test1=false;
if (n_secret<0) limita_stanga=-5000;
limita_dreapta = 5000;
if(n>n_secret) limita_dreapta = n;
if (n!=n_secret) cout << " \n Ai gresit!"<<endl;
while (!test)
{
if(!test1)
if(n>n_secret)
{
limita_dreapta = n;
test1=true;
}
greseli+=1;
cout << " ----------------------------------" << endl;
cout << " Numerele introduse pana acum sunt: ";
afiseaza_vector(i, vector);
cout << endl << endl;
cout << " Incearca din nou: ";
Citire_incercare(n, i, vector);
if(n>n_secret && limita_dreapta>n)
limita_dreapta = n;
if (n<n_secret && n>limita_stanga)
limita_stanga = n;
cout << endl << endl << endl << endl << endl << endl;
clear_screen;
cout << endl;
cout << " Ai gresit!" << endl;
cout << " ----------------------------------" << endl;
cout << " AJUTOR: Numarul se afla intre " << limita_stanga << " si " << limita_dreapta << endl;
vector[i]=n; i++;
if (n==n_secret)
{
cout << endl << endl << endl << endl;
clear_screen;
cout << "Felicitari! Ai ghicit numarul secret! (" << n_secret <<")" <<endl;
cout << "Ai facut " << greseli << " greseli!" << endl;
mesaje(greseli);
cout << endl;
cout << "E-MAIL: butnaru.gheorghita@yahoo.com\n";
system("pause");
test = true;
}
if(greseli>=50)
{
cout << "Prea multe greseli / eroare de program";
exit(1);
}
}

}

int main()
{
sa_se_faca_lumina;
int n_secret, n;
int greseli=0;
Citire_n_secret(n_secret);
cout << " START" << endl << endl;
dasd(n,n_secret,greseli,vector);
}
User avatar
BGY95
Membru
Posts: 3
Joined: 27 Oct 2018, 10:06
Nivel cunoştinţe IT: 5

27 Oct 2018, 12:34

Modificat: Genereaza numarul automat, nu mai trebuie tastat la inceputul programului.
Genereaza numere intre -100 si +100

#include <iostream>
#include <cstdlib>
#include <ctime>
#define clear_screen system("cls")
#define sa_se_faca_lumina system("color 5A")
using namespace std;

int vector[50];
void Welcome()
{
cout << " Bine ai venit!\n Jocul se numeste GHICESTE NUMARUL SECRET\n"<<endl;
}

int Citire_incercare(int &n, int i, int vector[])
{
cin >> n;
vector = n;
return n;
}
void afiseaza_vector(int i, int vector[])
{
for (int k=0;k<i;k++)
cout << vector[k] << " ";
}
void mesaje (int greseli)
{
if (greseli <= 3) cout << "FANTASTIC! Un scor foarte bun!";
if (greseli > 3 && greseli < 7) cout << "Se putea si mai bine...";
if (greseli >=7 && greseli <= 10) cout << "Hmmmm..... Nu e prea bine!";
if (greseli >10 && greseli <=15) cout << "Ai facut prea multe greseli!";
if (greseli >15) cout << "Foarte multe greseli!";
}
void dasd(int n, int n_secret, int greseli, int vector[])
{
clear_screen;
Welcome();
char lit, lit2;
int ad, admin = {1234};
cout << "Esti admin? D/d = afirmativ | Alta tasta pentru negativ" << endl;
cin >> lit;
if (lit=='D' || lit=='d')
{
cout << "Ok, sa vedem..." << endl;
cout << "Introdu parola de admin:" << endl;
cin >> ad;
if(ad==admin)
{
cout << "Esti admin!" << endl;
cout << "Numarul secret este: " << n_secret << endl;
cout << "Doresti sa inchizi programul? d/D = DA, n/N = NU" << endl;
cin >> lit2;
if(lit2=='d' || lit2=='D') exit(0);
if(lit2=='n'|| lit2=='N') cout << "Programul continua." << endl;
else cout << "Se ingora" << endl;
}
else cout << "Parola este incorecta! Nu esti admin!" << endl;
}
else
{
clear_screen;
cout << "Programul continua." << endl;
}
int i =0;
int limita_stanga, limita_dreapta;
cout << "Ghiceste numarul secret: ";
Citire_incercare(n,i,vector);
i++;
if (n==n_secret)
{
cout << "Felicitari! Ai ghicit numarul secret din prima incercare! (" << n_secret << ")" <<endl;
cout << "E-MAIL: butnaru.gheorghita@yahoo.com\n";
exit(0);
}
bool test = false, test1=false;
if (n_secret<0) limita_stanga=-100;
limita_dreapta = 100;
if(n>n_secret) limita_dreapta = n;
if (n!=n_secret) cout << " \n Ai gresit!"<<endl;
while (!test)
{
if(!test1)
if(n>n_secret)
{
limita_dreapta = n;
test1=true;
}
greseli+=1;
cout << " ----------------------------------" << endl;
cout << " Numerele introduse pana acum sunt: ";
afiseaza_vector(i, vector);
cout << endl << endl;
cout << " Incearca din nou: ";
Citire_incercare(n, i, vector);
if(n>n_secret && limita_dreapta>n)
limita_dreapta = n;
if (n<n_secret && n>limita_stanga)
limita_stanga = n;
cout << endl << endl << endl << endl << endl << endl;
clear_screen;
cout << endl;
cout << " Ai gresit!" << endl;
cout << " ----------------------------------" << endl;
cout << " AJUTOR: Numarul se afla intre " << limita_stanga << " si " << limita_dreapta << endl;
vector=n; i++;
if (n==n_secret)
{
cout << endl << endl << endl << endl;
clear_screen;
cout << "Felicitari! Ai ghicit numarul secret! (" << n_secret <<")" <<endl;
cout << "Ai facut " << greseli << " greseli!" << endl;
mesaje(greseli);
cout << endl;
cout << "E-MAIL: butnaru.gheorghita@yahoo.com\n";
system("pause");
test = true;
}
if(greseli>=50)
{
cout << "Prea multe greseli / eroare de program";
exit(1);
}
}

}

int main()
{
sa_se_faca_lumina;
int n_secret, n;
int greseli=0;
srand(time(NULL));
n_secret = (rand()%200)-99;
cout << " START" << endl << endl;
dasd(n,n_secret,greseli,vector);
}
Post Reply

Return to “Programare”