Hahli1994
Hahli1994

Reputation: 19

C++ Cootie game errors

I finished the code for the most part, I'm supposed to create a cootie game which adds arms legs heads etc to each players cootie depending on the dice roll which they throw. I've been getting errors however when I try to compile it and I'm not exactly sure what it is I'm supposed to do to rid them. I'm absolutely terrible at programming but I will try my best to understand your responses, Thankyou so much for your help!

Here are the errors:

In file included from main.cpp:8:
Player.h:14: error: ‘cootie’ does not name a type
Player.h:15: error: ‘Dice’ does not name a type
In file included from Player.cpp:1:
Player.h:14: error: ‘cootie’ does not name a type
Player.h:15: error: ‘Dice’ does not name a type
Player.cpp: In member function ‘void Player::takeTurn()’:
Player.cpp:24: error: ‘dice’ was not declared in this scope
Player.cpp:25: error: ‘getRoll’ was not declared in this scope
Player.cpp:27: error: ‘monster’ was not declared in this scope
Player.cpp:29: error: expected `}' before ‘else’
Player.cpp: At global scope:
Player.cpp:29: error: expected unqualified-id before ‘else’
Player.cpp:31: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:32: error: expected unqualified-id before ‘else’
Player.cpp:34: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:35: error: expected unqualified-id before ‘else’
Player.cpp:37: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:38: error: expected unqualified-id before ‘else’
Player.cpp:40: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:41: error: expected unqualified-id before ‘else’
Player.cpp:43: error: expected constructor, destructor, or type conversion before ‘<<’ token
Player.cpp:44: error: expected declaration before ‘}’ token
Player.h:14: error: ‘cootie’ does not name a type
Player.h:15: error: ‘Dice’ does not name a type

Here is my code:

cootie.cpp:

 #include "cootie.h"
#include <iostream>
#include <string>
using namespace std;

string name;
int legs, heads, eyes, wings, bodies, antennas;

//accessors
string cootie::getName(){return name;}
int cootie::getLegs(){return legs;}
int cootie::getHeads(){return heads;}
int cootie::getEyes(){return eyes;}
int cootie::getWings(){return wings;}
int cootie::getBodies(){return bodies;}
int cootie::getAntennas(){return antennas;}

//mutators
void cootie::setName(string na){
    name = na;
}
void cootie::setLegs(int l){
    legs = l;
}
void cootie::setHeads(int h){
    heads = h;
}
void cootie::setEyes(int e){
    eyes = e;
}
void cootie::setWings(int w){
    wings = w;
}
void cootie::setBodies(int b){
    bodies = b;
}
void cootie::setAntennas(int a){
    antennas = a;
}

cootie.h:

#ifndef COOTIE_H
#define COOTIE_H

#include <iostream>
#include <string>

using namespace std;

class cootie{
private:
    //listing members?
    string name;
    int legs, heads, eyes, wings, bodies, antennas;


public:
    //constuctors
    //default constructors
    cootie (){
        name = "undefined";
        legs = 0;
        heads = 0;
        eyes = 0;
        wings = 0;
        bodies = 0;
        antennas = 0;
    }
    //non-defaultconstructors
    cootie(string na, int l, int h, int e, int w, int b, int a) {
        name = na;
        legs = l;
        heads = h;
        eyes = e;
        wings = w;
        bodies = b;
        antennas = a;
    }

    string getName();
    int getLegs();
    int getHeads();
    int getEyes();
    int getWings();
    int getBodies();
    int getAntennas();

    void setName(string na);
    void setLegs(int l);
    void setHeads(int h);
    void setEyes(int e);
    void setWings(int w);
    void setBodies(int b);
    void setAntennas(int a);
};

#endif /* defined(____cootie__) */

Dice.cpp:

#include "Dice.h"

#include <cstdlib>
#include <ctime>
//#include "cootie.h"
#include <iostream>
//#include <string>
using namespace std;

Dice::Dice(int sides) :
    sides(sides)
{}


float Dice::getRoll() {
    return ((rand() % sides) + 1);
}

void Dice::randomize (){
    srand((unsigned)time(NULL)); // or is it null?
}

Dice.h:

#ifndef DICE_H
#define DICE_H


class Dice
{
    public:
        Dice(int sides);
        float getRoll();

        static void randomize(); //called once
    protected:
    private:
        int sides;
};

#endif // DICE_H

Player.cpp:

#include "Player.h"
#include "cootie.cpp"
#include "Dice.h"
#include <iostream>
#include <string>
using namespace std;
//Player::Player(string name)
//{
  //  name = n;
  //ctor
//}

//accessors
//string Player::getName(){
//return name;
//}
//mutators
//void Player::setName(string n){
//    name = n;
 //   }

void Player::takeTurn()
{
    dice.randomize();
    float f = getRoll();
    if (f == 1)
    monster.setLegs(monster.getLegs()+1);
    cout << "add a leg to cootie"<< endl;
    else if (f == 2)
    monster.setHeads(monster.getHeads()+1);
    cout << "add a head to cootie"<< endl;
    else if (f == 3)
    monster.setEyes(monster.getEyes()+1);
    cout << "add an eye to cootie"<< endl;
    else if (f == 4)
    monster.setWings(monster.getWings()+1);
    cout << "add a wing to cootie"<< endl;
    else if (f == 5)
    monster.setBodies(monster.getBodies()+1);
    cout << "add a body to cootie"<< endl;
    else if (f == 6)
    monster.setAntennas(monster.getAntennas()+1);
    cout << "add an antenna to cootie"<< endl;
}

Player.h:

#ifndef PLAYER_H
#define PLAYER_H


class Player
{
    public:
        Player();
        void takeTurn();
 //       void getName(string na);
 //       void setName();
    protected:
    private:
       cootie monster;
       Dice dice(6);
 //       string name;
};

#endif // PLAYER_H

main.cpp:

#include "Player.h"
#include "cootie.h"
#include "Dice.h"
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

using namespace std;

int main (){
   // cootie c("R2D2", 1, 1,0,2,1,0);
cootie c;
int x;


    //Dice d(6);
    //cout << "regular dice" << d.getRoll() << endl;
    //Dice d20(20);
   // cout << "20 size dice" <<d20.getRoll() << endl;
    //Dice percentile(100);
    //cout << "Percentile size dice"<< percentile.getRoll() << endl;
    Player playerArray [2];// 2 player game
    while (x<3)
{
    for (x=0;x<2;x++)
    {
        playerArray[x].takeTurn();
        cout <<"Player "<< x;
    cout << "Cootie " << x << endl;
    cout << c.getLegs() << " Leg(s)" << endl;
    cout << c.getHeads() << " Head(s)" << endl;
    cout << c.getEyes() << " Eye(s)" << endl;
    cout << c.getWings() << " Wing(s)" << endl;
    cout << c.getBodies() << " Bodie(s)" << endl;
    cout << c.getAntennas() << " Antenna(s)" << endl;

    }
}
cout << "im done here" <<endl;

    return 0;
}

Upvotes: 0

Views: 426

Answers (2)

Monkeyanator
Monkeyanator

Reputation: 1416

Judging from the errors, you forgot to import some header files.

It also seems like there is another error later on down the road involving an else statement. I'd say this is probably a syntax error you've made. Your compiler should make it reasonably easy for you to isolate this one.

Upvotes: 1

Potatoswatter
Potatoswatter

Reputation: 137870

There's obviously a lot to fix there.

The first problem,

Player.h:14: error: ‘cootie’ does not name a type

indicates that cootie.h should be included from Player.h so the declaration of class cootie is visible when it is used.

Upvotes: 3

Related Questions