Code:
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<string>
using namespace std;
int length, index1, index2, input, num, i, tries = 0;
string guess;
char temp;
char SYMBOLS[4] = {'!', '&', '@', '%'};
void Seed()
{
srand(time(0));
}
int GetRandNum(int max)
{
return rand() % max;
}
int main()
{
Seed();
while((input != 1) && (input != 3))
{
cout << "Welcome to the game of Logic!" << endl;
cout << "What would you like to do?" << endl << endl;
cout << "1 - Play the game of Logic" << endl;
cout << "2 - Read instructions on how to play Logic" << endl;
cout << "3 - Quit" << endl;
cin >> input;
switch(input)
{
case 1:
cout << "Enter the number of symbols you would like to guess" << endl;
cin >> length;
string sequence = "";
for (i = 0; i < length; ++i)
{
num = GetRandNum(4);
sequence += SYMBOLS[num];
index1 = (rand() % 3);
index2 = (rand() % 3);
temp = sequence[index1];
sequence[index1] = sequence[index2];
sequence[index2] = temp;
}
do
{
cout << "Guess the order in which the symbols are in" << endl;
cin >> guess;
if (guess != sequence)
{
++tries;
cout << "Try again" << endl;
cout << tries << endl;
}
else
{
cout << "You got it!" << endl;
}
}
while (guess != sequence);
system("PAUSE");
break;
}
}
system("PAUSE");
return 0;
}
Messed around with the %3 and stuff still sometimes came up with a space