Hello,
I am trying to get the return value from the next_number function up to the makefile function. I am getting an error that says next_number does not have a class type.
EDIT: the error is "return statement with a value, in function returning 'void'"
I don't understand why it says the function is void?
next_number is a private function. Do I need to do something different since it's private?
#include "utility.h"
#include "filer.h"
filer::filer()
{
//ctor
}
filer::~filer()
{
//dtor
}
//precondition: n, range, truly_random, and file_name have
//been set; truly_random is type bool, and determines whether
//the numbers are truly random, or pseudorandom
//postcondition: n random integers in the range 0-range,
//inclusive, have been written to a file named file_name,
//one per line;
void filer::makefile(int n, int range, bool truly_random, string file_name)
{
ofstream outstream;
outstream.open(file_name.c_str());
if (!truly_random){
for(int i = 0; i < n; i++){
outstream << next_number() << endl;
}
}
else if (truly_random){
srand(int(time(NULL)));
for(int i = 0; i < n; i++){
outstream << next_number() << endl;
}
}
else {
cout << "Improper choice." << endl;
}
outstream.close(); //Close the file
//precondition: range has been set to a nonnegative value
//postcondition: returns a random integer in the range
//0-range, inclusive
int next_number(int range);
int value = rand() % range + 1;[LIST=1]
[/LIST]
return value;
}