Any help on making random char code?
I need to create a random code that uses "abcde" and that does not repeat any letters, but I have no idea how to do that, I know how to make random numbers, but not chars, any help?
This is what I need them for:
Code:
#include <iostream>
#include <cstring>
#include <ctime>
using namespace std;
int main()
{
char code[6] = "abcde"; // here I want the ranom code
char icode[6];
char letter;
char opcion;
bool playagain = false;
int i = 0;
int correct = 0;
do
{
cout << "\t\t*RULES*\n\n";
cout << "1.- You do NOT speak about Fight Club.... lol.\n";
cout << "2.- You do NOT write in CAPS.\n";
cout << "3.- You do NOT write more than 5 lettrrs per guess.\n\n\n";
cout << "Try to guess a code I have thought of:\n";
do
{
icode[5] = '\0';
for (i = 0; i < 5; i++)
{
cin >> letter;
icode[i] = letter;
if (icode[i] == code[i])
{
correct++;
}
}
cout << "You had " << correct << " correct letters!\n";
if (!strcmp(code, icode))
{
cout << "You guessed the code!\n";
}
correct = 0;
} while (strcmp(code, icode));
cout << "Do you want to play again? (y/n)\n";
cin >> opcion;
playagain = (opcion == 'y' ? true : false);
} while (playagain);
return 0;
}