Now, I am sure there are more than 3 problems with this thing, and it's been sort of butchered into pieces with me attempting to solve this issue. Regardless, outside of the three problems I'd appreciate any input.

My book tasks me with creating a program for a zoo that allows them to keep track of how much food (in terms of weight) three of their monkeys ate, and then performs some calculations on those numbers.

The compiler is reporting 3 errors, on lines 118, 119 and 120.

each line has the same error "expected primary expression before 'Travis'", the only thing that changes is what it expects the expression before, on line 119 it's beat and on line 120 it's Ryo.

#include <iostream>
using namespace std;

class Monkey
{
    int ryosmall, beatsmall, travissmall;

    public:

    int eats[7];

    bool checkValid(int);
    int travissmallest(Monkey, int);
    int beatsmallest(Monkey, int);
    int ryosmallest(Monkey, int);
    int getTravis() {   return travissmall;  }
    int getBeat()   {   return beatsmall;   }
    int getRyo()    {   return ryosmall;    }
    //int leastAmount(Monkey, Monkey, Monkey);
    int total(Monkey, Monkey, Monkey);
    int average(Monkey, Monkey, Monkey);
};

bool Monkey::checkValid(int temp)
{
    if (temp <= 0)
        return false;
    else
        return true;
}

int Monkey::travissmallest(Monkey Travis, int travissmall)
{
    //static int monkey[3] = {9999, 9999, 9999};
    travissmall = 90000;
    for (int i = 0; i < 7; i++)
    {
        if (Travis.eats[i] < travissmall)
        {
             travissmall = Travis.eats[i];
        }
    }   return travissmall;
}

int Monkey::beatsmallest(Monkey Beat, int beatsmall)
{
    beatsmall = 90000;
    for (int i = 0; i < 7; i++)
    {
        if (Beat.eats[i] < beatsmall)
        {   beatsmall = Beat.eats[i]; }
    }   return beatsmall;
}

int Monkey::ryosmallest(Monkey Ryo, int Ryosmall)
{
    ryosmall = 90000;
    for (int i = 0; i < 7; i++)
    {
        if (Ryo.eats[i] < ryosmall)
        {   ryosmall = Ryo.eats[i]; }
    }   return ryosmall;
}

int Monkey::total(Monkey Travis, Monkey Beat, Monkey Ryo)
{
    static int eachdaytot[7];

    for (int i = 0; i < 7; i++)
    {   eachdaytot[i] = Travis.eats[i] + Beat.eats[i] + Ryo.eats[i]; };

    return *eachdaytot;
}

int Monkey::average(Monkey Travis, Monkey Beat, Monkey Ryo)
{
    static int eachdayavg[7];

    for (int i = 0; i < 7; i++)
    {   eachdayavg[i] = Travis.eats[i] + Beat.eats[i] + Ryo.eats[i] / 3; };

    return *eachdayavg;
}

int main()
{
    int temp;
    Monkey Travis, Beat, Ryo, general;

    cout << "What was the least amount of food (pints) eaten by Travis this week?" << endl;
        for (int i = 0; i < 7; i++)
        {
            cin >> temp;
            if (Travis.checkValid(temp) == true)
            {   Travis.eats[i] = temp;  }
            else
            {   i -= 1;     }
        }
    cout << "What was the least amount of food (pints) eaten by Beat this week?" << endl;
        for (int i = 0; i < 7; i++)
        {
            cin >> temp;
            if (Beat.checkValid(temp) == true)
            {   Beat.eats[i] = temp;  }
            else
            {   i -= 1;     }
        }
    cout << "What was the least amount of food (pints) eaten by Ryo this week?" << endl;
        for (int i = 0; i < 7; i++)
        {
            cin >> temp;
            if (Ryo.checkValid(temp) == true)
            {   Ryo.eats[i] = temp;  }
            else
            {   i -= 1;     }
        };

    general.travissmallest(Monkey Travis);
    general.beatsmallest(Monkey Beat);
    general.ryosmallest(Monkey Ryo);
    cout << "Travis' smallest meal was " << general.getTravis() << cout << " Beat's was " << general.getBeat()
    << " Ryo's was " << general.getRyo() << endl;

    for (int i = 0; i < 7; i++)
    {   cout << "The total food eaten this day by the group " << general.total (Travis, Beat, Ryo) << endl;  }

    for (int i = 0; i < 7; i++)
    {   cout << "The average food eaten this day by the group " << general.average (Travis, Beat, Ryo) << endl;  }
};

Recommended Answers

All 4 Replies

your missing another parameter eg int travissmall etc. and where did you declare general ?

EDIT: nevermind i found it

you need to rework your classes
int Monkey::travissmallest(Monkey Travis, int travissmall)
Monkey is a class not a variable and Travis which is defined in int main() is an object of class Monkey so Monkey Travis has no effect in that statement except to declare Travis in the scope of the function.

heres a tip each object has its own members this will save you lines and lines and lines of code especially in large projects i had to find this out the hard way.
I E

class me{
int x;};

int main()
{
me d,r,b;
d.x=2;
r.x=44;
b.x=32;
cout<<d.x<<endl<<r.x<<endl<<b.x;
}
// out put is 
// 2
// 44
// 32

actually i just found your problem general.travissmall(Monkey Travis);
also that function only uses the object with in the scope of the function so that when you modify Travis in int main() it has no affect in that function(side note : this applys to the other functions that follow similar format).
if i were you i would just recode the whole thing i know it sounds like a lot but think of it this way how fast do you type? and how long does it take you to write 20 lines of code? i can write 20 lines of code in like 5 mins your hundred odd some line would take me about ten minutes of nonstop typing if i could even do that which i cant because of bad hand eye coordination. so i bet you could retype it in at the most 20 minutes unless your like me and need a few minutes to consider the logical part of the program.
you can't declare an object with an object in it unless its from another class :)
silly
Also if anyone wants to correct me on anything that would be awesome :)

Wow, I cannot believe I did that. Thanks for pointing that out. I think I may restart, and might try re-writing my pseudo code as well.

if i don't have any homework tommorrow ill help you out on rewriting the classes if you want i need some more experience any way because right now the only thing keeping me from learning more is that i don't have any challenges. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.