can someone please give me a hand in adding arrays to my game here is what i have.
#include <iostream>
#include <string>
#include <time.h>
#include <cstdlib>
using namespace std;
void initMessages()
{
const char* END_OF_ARRAY = "end_of_array";
const int YES_MSG = 0;
const int NO_MSG = 1;
}
char* getMessage(const int messageId)
{
return messages[messageId].c_str();
}
int main()
{
int a,b,c,d,e,f,g; // Declaration of strings
string str1, str2, str3;
e = 1;
string theArray[2];
theArray[3] = END_OF_ARRAY;
while (e == 1)
{
g = 11; // G represents the Varible counter
a = 0; // Random num generated from zero
f = 0;
string str2 = "yes";
string str3 = "no";
for(c = 4; c <=100; c++)
{
srand((unsigned)time(NULL)); // Set a seed for random-num Generator.
a = (rand() % 100) +1;
}
d = 11;
while (d > 0)
{
g = g-1;
d = d-1;
if (d == 10)
{
cout << "Number of tries left: " << g << endl << endl;
cout << "Hello" << endl;
cout << "Welcome to my Guessing Game" << endl;
cout << "Try to guess a number between 1 and 100 in under 10 tries: ";
cin >> b;
}
else if ( (d == 9) && (b == a))
{
cout << "Number of tries left: " << g << endl << endl;
cout << "Good Job" << endl;
d = 0;
}
else if ( (d < 10) && (b < a))
{
cout << "Number of tries left: " << g << endl << endl;
cout << "Your guess was too low, why don't you guess again? ";
cin >> b;
}
else if ( (d < 10) && (b > a))
{
cout << "Number of tries left: " << g << endl << endl;
cout << "Your guess was too high, why don't you guess again? ";
cin >> b;
}
else if ( (d < 10) && (b == a))
{
cout << "Number of tries left: " << g << endl << endl;
cout << "Took you long enough!!! You finally got it!" << endl;
d = 0;
}
}
if ( (d == 0) && (b != a))
{
cout << "The number was: " << a << endl << endl;
cout << "Too Bad was your brain tired?. You didn't manage to guess it.\nWas this your first time playing?";
}
else if ( (d == 0) && (b == a))
{
cout << "Number of tries left: " << g << endl << endl;
cout << "CONGRATULATIONS!!! You finally got it!" << endl;
d = 0;
}
while (f != 1)
{
cout << endl << endl << "Would you like to play again? (yes/no) ";
cin >> str1;
if (str1.compare(str2) == 0)
{
e = 1;
f = 1;
}
else if (str1.compare(str3) == 0)
{
e = 2;
f = 1;
}
else
{
cout << "Can you hit yes or no?";
}
}
}
cin.get();
cin.get();
return 0;
}