0
Challenge: Make C++ code that generates random password, so the player need to guess it.
Make code that generates password so the player needs to guess it. make it in C++
4 Answers
+ 17
//=============================
// Casual rolling dice game!
// Done for : xX randomryze Xx
// By : Babak Sheykhan
//=============================
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<size_t>(time(0)));
/*--- Dice number generator ---*/
int d_1 = 1 + rand() % (6 - 1 + 1);
int d_2 = 1 + rand() % (6 - 1 + 1);
/*--- User's choices ---*/
int guess_1 = 0;
int guess_2 = 0;
/*--- Flags ---*/
bool isFirst = false;
bool isSecond = false;
bool isBoth = false;
do { cout << "Your guess for first dice: "; cin >> guess_1; } while (guess_1 > 6);
do { cout << "Your guess for second dice: "; cin >> guess_2; } while (guess_2 > 6);
cout << endl;
if (guess_1 == d_1) {
cout << "Your first guess was nice! " << d_1 << " == " << guess_1 << endl;
isFirst = true;
}
else cout << "Your first guess sucks!\n";
if (guess_2 == d_2) {
cout << "Your second guess was nice! " << d_2 << " == " << guess_2 << endl;
isSecond = true;
}
else cout << "Your second guess sucks!\n";
if (isFirst && isSecond) cout << "You won $100!\n";
else if (isFirst || isSecond) cout << "You won $50!\n";
else cout << "Get out of here! :D\n";
}
[https://www.jdoodle.com/embed/v0/cpp/gcc-5.3.0/abX]
[https://code.sololearn.com/c5Jo1XKaE9Cj]
+ 8
old code.
could be used like you say pretty easy. but it may be hard to guess the password
https://code.sololearn.com/cFxdiCUu5OG2/?ref=app
+ 6
Bad idea
+ 5
Thats why its a bad idea.