>Main returns an int:
Are you in the right thread?
Printable View
>Main returns an int:
Are you in the right thread?
I made some minor changes to the example I posted (changed variable names, added an extra call to rand, since the first number is always low on my machine (probably due to the seed used for srand()).
Code:#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
int guess;
//Seed the pseudo random number generator. Do this only once.
srand(time(NULL));
//Throw away first number generated (always low on my machine)
int number = rand();
//Generate a number between 1 and 100
number = static_cast<int>(1 + rand() / (RAND_MAX + 1.0) * 100);
do {
cout<<"Please input a number: " << flush;
cin>> guess;
cin.ignore();
cout<<"You inputted: "<< guess << "\n";
cin.ignore();
if ( guess < number )
cout<< " You are too low\n";
else if ( guess > number )
cout<< " You are too high\n";
} while (guess != number);
cout<< " Congrats you win!!\n";
cin.get();
}
>> Main returns an int
Perhaps you are referring to the lack of a return 0? That is not necessary for the main function. Zero is returned automatically if the function ends without a return statement.
>Perhaps you are referring to the lack of a return 0?
I hadn't thought of that, I bet that's to what Ideswa indeed was referrring. I normally add the return 0; also just for consistency.
>Perhaps you are referring to the lack of a return 0?
I was trying to get him to say it explicitly. Vague good advice is no better than bad advice. ;)
Yea thanks for the catch, i forget to return, but i should just start doing it and remembering it. Also anyone have any sites or tutorials on small games that are used in examples. Most books like my textbook C++ learning by deitel, gives me some stupid gradebook example which I hate.