Original Post
Can you guys check it and see if there's anything I could've done better, or if my code structure is sloppy? Thanks! The rand, srand, and time things were all new to me. It was kind of just copied from a tutorial. I sort of got what the tutorial was saying, but I have a C++ book coming in tomorrow, so I'll completely learn it then ;) EDIT*: This may be nit-picky, but I think I'm going to make the "Too Low" and "Too High" into "Too Low." and "Too High." (added periods). So, if that's the only thing you'd correct about it, I already have it covered, so no need to post ;)
#include <time.h>
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
srand(time(NULL));
a = rand() % 21;
cout << " GUESS THE NUMBER GAME!\n";
cout << " an unoriginal idea coded by Kegan Walsh\n\n\n\n";
while (a!=b)
{
cout << "Guess a number between 1 and 20.\n";
cout << "> ";
cin >> b;
cout << "\n";
if (a>b)
{
cout << "Too low\n\n";
}
if (a<b)
{
cout << "Too high\n\n";
}
if (a==b)
{
cout << "That's right!\n\n";
system("Pause");
}
if (b<1)
{
cout << "Error: That number is below the given range.\n\n";
}
if (b>20)
{
cout << "Error: That number exceeds the given range.\n\n";
}
}
}