myromance123
October 6th, 2009, 03:24 PM
Hopefully i posted this in the right area (sorry if i didnt).
Hey there. Learning C++ from C++ For Dummies All-In-One Second edition where they teach it with Codeblocks (the reason why i bought it).
Ok, my problem is basically I get an error as such when building:
error; 'rand' was not declared in this scope
Here's my sourcode (slightly modified from the books version. Just added a prototype for the function).
rand() is located in the GetSecretCode() function :)
#include <iostream>
#include <sstream>
using namespace std;
string *GetSecretCode();
int main()
{
string *newcode;
int index;
for ( index = 0; index < 10; index++ )
{
newcode = GetSecretCode();
cout << newcode << endl;
}
cout << "All done here" << endl;
return 0;
}
string *GetSecretCode()
{
string *code = new string;
code->append("CR");
int randomnumber = rand();
ostringstream converter;
converter << randomnumber;
code->append(converter.str());
code->append("NQ");
return code;
}
What am I missing code wise?
something I didn't "#include" ?
Hey there. Learning C++ from C++ For Dummies All-In-One Second edition where they teach it with Codeblocks (the reason why i bought it).
Ok, my problem is basically I get an error as such when building:
error; 'rand' was not declared in this scope
Here's my sourcode (slightly modified from the books version. Just added a prototype for the function).
rand() is located in the GetSecretCode() function :)
#include <iostream>
#include <sstream>
using namespace std;
string *GetSecretCode();
int main()
{
string *newcode;
int index;
for ( index = 0; index < 10; index++ )
{
newcode = GetSecretCode();
cout << newcode << endl;
}
cout << "All done here" << endl;
return 0;
}
string *GetSecretCode()
{
string *code = new string;
code->append("CR");
int randomnumber = rand();
ostringstream converter;
converter << randomnumber;
code->append(converter.str());
code->append("NQ");
return code;
}
What am I missing code wise?
something I didn't "#include" ?