Hello!
My project for CS class is to create a program that generates a random number and prompts the user to guess it. Though, to me, it seems as if I have all the parts, it won't compile. These are the error I keep getting (I have no idea how to fix them):
Prog3.cpp: In function ‘int main()’:
Prog3.cpp:20:4: error: ‘cout’ was not declared in this scope
Prog3.cpp:20:4: note: suggested alternative:
In file included from Prog3.cpp:6:0:
/usr/include/c++/4.7/iostream:62:18: note: ‘std::cout’
Prog3.cpp:27:39: error: ‘endl’ was not declared in this scope
Prog3.cpp:27:39: note: suggested alternative:
In file included from /usr/include/c++/4.7/iostream:40:0,
from Prog3.cpp:6:
/usr/include/c++/4.7/ostream:562:5: note: ‘std::endl’
Prog3.cpp:28:4: error: ‘cin’ was not declared in this scope
Prog3.cpp:28:4: note: suggested alternative:
In file included from Prog3.cpp:6:0:
/usr/include/c++/4.7/iostream:61:18: note: ‘std::cin’
And here's the actual code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <ctime>
#include <cstdlib>
int main()
{
int guess;
int tries = 0;
int randomN;
randomN= rand()%100 + 1;
srand(time(0));
int numbercases;
numbercases= 0;
cout << "The computer has chosen a random number. You have to "
<< "guess what it is.";
//Here, the user will take their guess to see what the random
//number is.
do
{
cout << "What is your guess?: " << endl;
cin >> guess;
numbercases++;
if (guess < randomN)
{
cout << "Aw! Too low! Try again, okay?" << endl;
}
else if (guess > randomN)
{
cout << "Ugh! Too high! Try again." << endl;
}
if (guess == randomN)
{
cout << "That's it; you got it!" << endl;
}
else if (guess < 0)
cout << "Game over. You've given up." << endl;
} while (guess != randomN);
return 0;
}
|
If I'm missing a library, too, could someone let me know? I feel like I am, but I don't know them all.