Ok, Ok I have made it much better, only problem is, I cant think of a way to make a random code that has only the letters "abcde" and that does not repeat them, Any ideas?
BTW this what I have now:
Code:
#include <iostream>
#include <cstring>
#include <ctime>
using namespace std;
int main()
{
char code[6] = "abcde";
char icode[6];
char letter;
char opcion;
bool playagain = false;
int i = 0;
int correct = 0;
do
{
do
{
icode[5] = '\0';
cout << "Try to guess a code I have thought of:\n";
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;
}
Yes I know its a horrible code, but I make functions and all that to make it look better latter...