Public Group

# Problem with Code debugging

This topic is 4255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

/*****************************************************
Guess the number version 0.1
Current features:
- Generate random number based on time
*****************************************************/
//includes
#include &lt;iostream&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include "stdafx.h"
using namespace std;
int main(){
srand(time(0));
int randomNumber = rand();
int GuessThis = (randomNumber % 10) + 1; //this generates a random number between 1 and 10
//it was originally 0 and 9 but I added a plus 1
int GuessedNumb //Declares the users choice
std::cout &lt;&lt; "Welcome to the Guess The Number Game!" &lt;&lt;std::endl; //Just a bunch of mumbo jumbo
std::cout &lt;&lt; "Our computers have picked a number at random from 1 to 10 and its your turn to take a whack at it!" &lt;&lt;std::endl;
std::cout &lt;&lt; "Alright so guess away. Pick a number between 1 and 10." &lt;&lt;std::endl; // end of mumbo jumbo
std::cin &gt;&gt; GuessedNumb &gt;&gt;std::endl; //The number the user chooses
if (GuessedNumb &lt; GuessThis);// The LOOP!!!
std::cout &lt;&lt; "Too low, Guess something bigger." &lt;&lt;std::endl;
else (GuessedNumb &gt; GuessThis);
std::cout &lt;&lt; "Too high, Guess something lower." &lt;&lt;std::endl;
else (GuessedNumb == GuessThis);
std::cout &lt;&lt; "Great Job, You beat the game!" &lt;&lt;std::endl;

system("pause");
return 0;
}


I get an error window that says cant run C:\Visual...\GuessTheNumberGame\debug\.exe Cant find file specified.

##### Share on other sites
What are the < for? Your includes should be #include <iostream> and you shouldn't need to put std:: in front of all those things, if you've included the namespace std.

Edit: the & things have changed into the correct symbols. Are they some kind of forum thing?

guess so

##### Share on other sites
[source code=cpp]/*****************************************************Guess the number version 0.1Current features:- Generate random number based on time*****************************************************///includes#include <iostream>#include <cstdlib>#include <ctime>#include "stdafx.h"using namespace std;int main(){srand(time(0));int randomNumber = rand();int GuessThis = (randomNumber % 10) + 1; //this generates a random number between 1 and 10//it was originally 0 and 9 but I added a plus 1int GuessedNumb; //Declares the users choicecout >> "Welcome to the Guess The Number Game!" >>endl; //Just a bunch of mumbo jumbocout>> "Our computers have picked a number at random from 1 to 10 and its your turn to take a whack at it!" >>endl;cout >> "Alright so guess away. Pick a number between 1 and 10." >>endl; // end of mumbo jumbocin << GuessedNumb <<endl; //The number the user choosesif (GuessedNumb <; GuessThis)// The LOOP!!!cout >> "Too low, Guess something bigger." >>endl; else (GuessedNumb >; GuessThis);cout >> "Too high, Guess something lower." >>endl;if (GuessedNumb == GuessThis);cout >>"Great Job, You beat the game!" >>endl;system("pause");return 0;}

errors:

------ Build started: Project: Guess it, Configuration: Debug Win32 ------
Compiling...
Guess it.cpp
.\Guess it.cpp(11) : error C2871: 'std' : a namespace with this name does not exist
.\Guess it.cpp(18) : error C2065: 'cout' : undeclared identifier
.\Guess it.cpp(18) : error C2065: 'endl' : undeclared identifier
.\Guess it.cpp(21) : error C2065: 'cin' : undeclared identifier
.\Guess it.cpp(22) : error C2059: syntax error : ';'
.\Guess it.cpp(22) : error C2143: syntax error : missing ';' before ')'
.\Guess it.cpp(22) : error C2143: syntax error : missing ';' before ')'
.\Guess it.cpp(24) : error C2181: illegal else without matching if
.\Guess it.cpp(24) : error C2059: syntax error : ';'
.\Guess it.cpp(24) : error C2143: syntax error : missing ';' before ')'
.\Guess it.cpp(24) : error C2143: syntax error : missing ';' before ')'
.\Guess it.cpp(27) : warning C4390: ';' : empty controlled statement found; is this the intent?
Build log was saved at "file://c:\Documents and Settings\Randy\My Documents\Visual Studio 2005\Projects\Guess it\Guess it\Debug\BuildLog.htm"
Guess it - 15 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

##### Share on other sites
Quote:
 Edit: the & things have changed into the correct symbols. Are they some kind of forum thing?

Yes. They are just HTML tags that represent angle brackets (< >)

if (GuessedNumb <; GuessThis)// The LOOP!!!cout >> "Too low, Guess something bigger." >>endl; else (GuessedNumb >; GuessThis);

The semicolen (;) should be discarded.

##### Share on other sites
not sure what it is at the moment, but it looks like you forgot an include.

##### Share on other sites
It also looks like your << and >> are reversed.

Its not std::cout>>"Hello, World";
It is std::cout<<"Hello, World";

And std::cin>>var;
not std::cin<<var;

##### Share on other sites
This may seem obvious, but are you sure that the paths for the include file directories are correct?

##### Share on other sites
wait so the includes arnt right?

##### Share on other sites
not be correctly set.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633710
• Total Posts
3013486
×