Hello, I'm just starting to toy with programming in my spare time.
I was watching a video about a random number game and tried to write the program into codeblocks but it's giving me errors that I don't understand.
This is the video:
http/www.youtube.com/user/reconnetworks#p/u/3/cW3c-AO4g7s
It works for him, but it's not working for me.
This is my code:
1 #include<iostream>
2 #include<ctime>
3 using namespace std;
4
5 int main(void)
6 {
7 int iGumballs;
8 int iUserguess;
9 int iGuesses = 0;
10
11 while(true)
12 {
13
14 system("CLS");
15 cin.clear();
16 iGuesses = 0;
17
18 srand(static_cast<unsigned_int>(time(0)));
19 iGumballs = rand()%1000+1;
20 cout << "How many gumballs are in the jar?" << endl;
21
22 do
23 {
24 cout << "Enter your guess: ";
25 cin >> iUserguess;
26 if(iUserguess > iGumballs)
27 {
28 cout << "Too high" << endl << endl;
29 }
30 if(iUserguess < iGumballs)
31 {
32 cout << "Too low" << endl << endl;
33 }
34 iGuesses ++;
35
36 }while(iUserguess > iGumballs || iUserguess < iGumballs);
37 cout << "You're Right, yay!" << endl << endl;
38 cout << "You took " << iGuesses << " guesses" << endl << endl;
39 system("PAUSE");
40 }
41 return 0;
42}
These are my errors:
line 1 error: iostream: No such file or directory
line 2 error: ctime: No such file ore directory
line 3 error: expected '=', ',', ';', 'asm' or '_attribute_' before 'namespace'
line 11 error: 'true' undeclared (first use in this function)
line 11 error: (Each undeclared identifier is reported only once
line 11 error: for each function it appears in.)
line 14 warning: implicit declaration of function 'system'
line 15 error: 'cin' undeclared (first use in this function)
line 18 warning: implicit declaration of function 'srand'
line 18 error: 'static_cast' undeclared (first use in this function)
line 18 error: 'insigned_int' undeclared (first use in this function)
line 18 warning: implicit declaration of function 'time'
line 19 warning: implicit declaration of function 'rand'
line 20 error: 'cout' undeclared (first use in this function)
line 20 error: 'endl' undeclared (first use in this function)
I don't understand what it's doing. Why doesn't it recognize iostream and ctime? It does that with some programs but not others.
Can you explain what it's doing? Thanks
I was watching a video about a random number game and tried to write the program into codeblocks but it's giving me errors that I don't understand.
This is the video:
http/www.youtube.com/user/reconnetworks#p/u/3/cW3c-AO4g7s
It works for him, but it's not working for me.
This is my code:
1 #include<iostream>
2 #include<ctime>
3 using namespace std;
4
5 int main(void)
6 {
7 int iGumballs;
8 int iUserguess;
9 int iGuesses = 0;
10
11 while(true)
12 {
13
14 system("CLS");
15 cin.clear();
16 iGuesses = 0;
17
18 srand(static_cast<unsigned_int>(time(0)));
19 iGumballs = rand()%1000+1;
20 cout << "How many gumballs are in the jar?" << endl;
21
22 do
23 {
24 cout << "Enter your guess: ";
25 cin >> iUserguess;
26 if(iUserguess > iGumballs)
27 {
28 cout << "Too high" << endl << endl;
29 }
30 if(iUserguess < iGumballs)
31 {
32 cout << "Too low" << endl << endl;
33 }
34 iGuesses ++;
35
36 }while(iUserguess > iGumballs || iUserguess < iGumballs);
37 cout << "You're Right, yay!" << endl << endl;
38 cout << "You took " << iGuesses << " guesses" << endl << endl;
39 system("PAUSE");
40 }
41 return 0;
42}
These are my errors:
line 1 error: iostream: No such file or directory
line 2 error: ctime: No such file ore directory
line 3 error: expected '=', ',', ';', 'asm' or '_attribute_' before 'namespace'
line 11 error: 'true' undeclared (first use in this function)
line 11 error: (Each undeclared identifier is reported only once
line 11 error: for each function it appears in.)
line 14 warning: implicit declaration of function 'system'
line 15 error: 'cin' undeclared (first use in this function)
line 18 warning: implicit declaration of function 'srand'
line 18 error: 'static_cast' undeclared (first use in this function)
line 18 error: 'insigned_int' undeclared (first use in this function)
line 18 warning: implicit declaration of function 'time'
line 19 warning: implicit declaration of function 'rand'
line 20 error: 'cout' undeclared (first use in this function)
line 20 error: 'endl' undeclared (first use in this function)
I don't understand what it's doing. Why doesn't it recognize iostream and ctime? It does that with some programs but not others.
Can you explain what it's doing? Thanks