Tuesday, May 22, 2018

Can anyone explain my error from code blocks C++

I'm trying to create a classes in separate files using codeblocks. I get the error in function '_start' undefined reference to 'main'. I'm sure its a linkage problem but can't see where. In my program I’m trying to get a die, let the user decide how many sides the dice has, then roll the die a user specified amount of times.



die.h  file///////////////////////////////////

#include
#include
#ifndef DIE_H
#define DIE_H


using namespace std;

class die{

public:

die();//function prototype

int numsides;//member
void setNumsides(int numsides_);//setter

int getNumsides();// getter for size of dice

int value;
void setValue(int value_, int numsides_);
int getValue();

int roll;
void setroll(int roll_);
int getroll();


};
#endif// DIE_H


die.cpp//////////////////////////////////////////

#include "die.h"
#include
#include
#include /* srand, rand */

#include /* time */



using namespace std;


die::die()
{
//ctor

}
void die::setroll(int roll_)
{
roll=roll_;
}

int die::getroll()//amount o rolls
{
cout << "enter the ammont of rolls you would like" << endl;
cin >> roll;//amount of rolls you want

return roll;

}

void die::setValue(int value_, int numsides_)
{
value=value_;
numsides=numsides_;
}


int die::getValue()//get value function
{
//int roll;
value = (rand() % numsides) + 1;//sets roll value
return value;
}

void die::setNumsides(int numsides_)
{
numsides=numsides_;

}

int die::getNumsides()//get num of sides
{
cout << "how big of a dice would you like to roll " << endl;
cin >> numsides;//use this to determine dice

if(numsides < 4){//if dice is less than 4
cout << "Error has to be bigger than " << numsides << endl;
numsides = 6;//change to six sided dice

}
return numsides;
}


exercise1.cpp my main class/////////////////////////////////////


#include
#include /* srand, rand */

#include
#include "die.h"

using namespace std;

int main()
{
die mydice;//create an object dice

mydice.getNumsides();//gets sides of dice


mydice.getValue();//gets amount of rolls

mydice.getroll();//rolls the dice value times


return 0;
}

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...