Guessing Game Problem

Started by
12 comments, last by GarciaBackhoff 12 years ago
Ok changed everything you have stated, but it still marks something wrong with the <iostream>.

//Guess my Number (inverted)
//The computer will guess your number
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
int myNumber;
char yorn;
cout <<"Enter a number between 1 and 10: ";
cin >> myNumber;
cout <<"\nYou chose "<<myNumber <<" as your number.";

srand(time(0));
do
{
int theNumber = rand() % 10 + 1;
cout <<"Is your number "<<theNumber<<"? (y/n)";
cin >> yorn;
} while ((yorn != 'y') || (yorn !='Y'));
cout <<"I won !";
return 0;
}


This is what it marks.


C:\Users\Guillermo\Desktop\C++\Learning\test.c|4|error: iostream: No such file or directory|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|5|error: cstdlib: No such file or directory|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|6|error: ctime: No such file or directory|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|8|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
C:\Users\Guillermo\Desktop\C++\Learning\test.c||In function 'main':|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|16|error: 'cout' undeclared (first use in this function)|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|16|error: (Each undeclared identifier is reported only once|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|16|error: for each function it appears in.)|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|17|error: 'cin' undeclared (first use in this function)|
||=== Build finished: 8 errors, 0 warnings ===|
Advertisement
Change the file to test.cpp (or test.cc). I would guess that the IDE is seeing the .c extension and attempting to use gcc (C compiler) instead of g++ (C++ compiler). The code you are trying is only valid C++.

Ok changed everything you have stated, but it still marks something wrong with the <iostream>.

//Guess my Number (inverted)
//The computer will guess your number
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{
int myNumber;
char yorn;
cout <<"Enter a number between 1 and 10: ";
cin >> myNumber;
cout <<"\nYou chose "<<myNumber <<" as your number.";

srand(time(0));
do
{
int theNumber = rand() % 10 + 1;
cout <<"Is your number "<<theNumber<<"? (y/n)";
cin >> yorn;
} while ((yorn != 'y') || (yorn !='Y'));
cout <<"I won !";
return 0;
}


This is what it marks.


C:\Users\Guillermo\Desktop\C++\Learning\test.c|4|error: iostream: No such file or directory|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|5|error: cstdlib: No such file or directory|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|6|error: ctime: No such file or directory|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|8|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'namespace'|
C:\Users\Guillermo\Desktop\C++\Learning\test.c||In function 'main':|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|16|error: 'cout' undeclared (first use in this function)|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|16|error: (Each undeclared identifier is reported only once|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|16|error: for each function it appears in.)|
C:\Users\Guillermo\Desktop\C++\Learning\test.c|17|error: 'cin' undeclared (first use in this function)|
||=== Build finished: 8 errors, 0 warnings ===|


Oh, you're using Dev C++, its old as **** and doens't actually compile standard C++ code.

try changing your includes to #include <iostream.h> <stdlib.h> and <time.h> (it might also work to rename the file test.cpp and not change any code if Dev C++ is better than i remembered).

Alternativly you could get a modern compiler.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
WORKED!
changed to codeblocks and changed extension.
Thanks guys

This topic is closed to new replies.

Advertisement