My project have grewn a bit now and I decided to split it up in several files. Although its still just one class its good practice.
The program works when its a single file but it doesnt when I break it up. Need help to see why.
creature.h
#ifndef CREATURE_INCLUDED
#define CREATURE_INCLUDED
const int TARGET_NUMBER = 20;
const int CELL_SIZE = 20;
const int CREATURES = 10;
class creature {
public:
creature(); //constructor
void randomizeCells();
void printCells();
int calculateTotal();
int calculateOffset();
int abs(int i); // makes sure a number if positive
private:
int cell[CELL_SIZE];
};
#endif
creature.cpp
#include "creature.h"
#include <iostream>
creature::creature() {
randomizeCells();
}
void creature::randomizeCells() {
// fill them with junk
for(int i = 0; i < CELL_SIZE; i++)
cell = rand()%2;
}
void creature::printCells() {
for(int i = 0; i < CELL_SIZE; i++)
cout << cell;
}
int creature::calculateTotal() {
// holder for the total number
int total = 0;
for(int i = 0; i < CELL_SIZE; i++)
total += cell;
return total;
}
int creature::calculateOffset() {
int worth = this->calculateTotal() - TARGET_NUMBER;
return abs(worth);
}
int creature::abs(int i) {
if(i >= 0)
return i;
if(i < 0) {
i *= -1;
return i;
}
}
When I try to run it now it complains about cout is undecleared, but iostream is included just a couple of lines above. What did I do wrong when I split up the project into smaller files?