here is my code:
#include <iostream>
#include <string>
#include <time.h>
#include <cstdlib>
#include <windows.h>
using namespace std;
void setcolor(unsigned short color) //The function that you'll use to
{ //set the colour
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hcon,color);
}
int main()
{
int a,b,c,d,e,f,g;
string str1, str2, str3;
e = 1;
while (e == 1)
{
g = 11;
a = 0;
f = 0;
string str2 = "yes";
string str3 = "no";
for(c = 4; c <=1000; c++)
{
srand((unsigned)time(NULL));
a = (rand() % 1000) +1;
}
d = 11;
while (d > 0)
{
g = g-1;
d = d-1;
if (d == 10)
{ setcolor (9);
system("CLS");
cout << "Number of tries left: " << g << endl << endl;
cout << "Try to guess a number between 1 and 1000 in under 10 tries: ";
cin >> b;
}
else if ( (d == 9) && (b == a))
{ setcolor (4);
system("CLS");
cout << "Number of tries left: " << g << endl << endl;
cout << "WOW!!! .__. You managed to get it on the first try!! That's AMAZING!!!!!!!" << endl;
d = 0;
}
else if ( (d < 10) && (b < a))
{ setcolor (5);
system("CLS");
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))
{ setcolor (15);
system("CLS");
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))
{ setcolor (11);
system("CLS");
cout << "Number of tries left: " << g << endl << endl;
cout << "CONGRATULATIONS!!! You finally got it! ^_^" << endl;
d = 0;
}
}
if ( (d == 0) && (b != a))
{ setcolor (12);
system("CLS");
cout << "The number was: " << a << endl << endl;
cout << "Well, I'm sorry. You didn't manage to guess it.\nWas this your first time playing?";
}
else if ( (d == 0) && (b == a))
{ setcolor (3);
system("CLS");
cout << "Number of tries left: " << g << endl << endl;
cout << "CONGRATULATIONS!!! You finally got it! ^_^" << endl;
d = 0;
}
while (f != 1)
{ setcolor (13);
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
{ setcolor (14);
system("CLS");
cout << "WOW! You really are stupid. -_- You can't even type yes or no....\nGo fall in a hole you waste of space!!\n";
}
}
}
return 0;
}
would anybody be able to comment on it and tell me what i could do to improve my overall programming and what i should do now to improve my knowledge of C++?
^_^ thanks in advance for your time and comments


Sign In
Create Account

Back to top









