monkey code

I'm pretty new to C++, and I think my code looks ok to run, but I can't figure out why it won't compile on X-Code without errors. I saw a message on the first semicolon on int findHighest();, I don't know why it won't work. If anyone can help me out, it would be very much appreciated.
The output should be:
1
2
3
4
5
6
7
8
9
10
11
12
13
Name     Day 1  Day 2  Day 3  Day 4  Day 5  Day 6  Day 7
_____   _______ ______ ______ ______ ______ _____ _______
Curly    45      33     55     66     77     88    100
Larry    88      77     66     55     44     33     22
Moe      44      55     11     66     77     88     99

Curly    66.2
Larry    55.0
Moe      62.8

On day 7 Monkey 1 ate the most food, 100 pounds.

On day 3 Monkey 3 ate the least food, 11 pounds.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  //  MonkeyLab
//
//  Created by Caroline on 10/21/16.






#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
double average = 0;
void printContents(string monkeyNames[NUM_MONKEYS],int table[][NUM_DAYS]);
void rowSum(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS]);
int findLowest(int table[][NUM_DAYS]);
int findHighest(int table[][NUM_DAYS]);

//************************************************************//
// this function tracks the eating habits of 3 baby monkeys  *
//************************************************************//

int main()
{
    
    string monkeyNames[NUM_MONKEYS] = { "Curly", "Larry", "Moe" };
    
    int table[NUM_MONKEYS][NUM_DAYS] = { { 45,33,55,66,77,88,100 },
        { 88,77,66,55,44,33,22 },
        { 44,55,11,66,77,88,99 }
    };
    
    printContents(monkeyNames,table);
    rowSum(monkeyNames,table);
    
    cout << "The lowest amount of food eaten was: " << findLowest(table) << " Pounds\n";
    cout << "The highest amount of food eaten was: " << findHighest(table) << " Pounds\n";
    
}
//************************************************************//
// this function prints the total food eaten by the monkeys  *
//************************************************************//
void printContents(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS])
{
    cout << "Name \tDay 1   Day 2   Day 3   Day 4   Day 5   Day 6   Day 7   " << endl;
    cout << "_____\t______  ______  ______  ______  ______  ______  ______\n";
    for (int r = 0; r < NUM_MONKEYS; r++)
    {
        cout << monkeyNames[r];
        for (int c = 0; c < NUM_DAYS; c++)
        {
            cout << "\t";
            cout << table[r][c];
        }
        cout << endl;
    }
    cout << endl;
}


//*************************************************************//
// this function prints the sums of the rows for each monkey   *
//*************************************************************//
void rowSum(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS])
{
    cout<<"Name \tAverage daily intake in pounds \n";
    cout << "_________________________________________________________________________\n";
    int totalRow=0;
    
    for(int r=0;r<NUM_MONKEYS;r++)
    {
        for(int c=0;c<NUM_DAYS;c++)
            
            totalRow=totalRow + table[r][c];
        
        cout<< monkeyNames[r] <<"\t"<< setw (1)<<(totalRow/NUM_DAYS) <<endl;
    }
    totalRow = 0;
}

//*************************************************************//
// this function finds the lowest amount eaten by the monkeys  *
//*************************************************************//

int findLowest(int table[][NUM_DAYS])
{
    int leastFood;
    int leastMonkey = 0;
    int leastDay = 0;
    int monkey = 0;
    leastFood = table[leastMonkey][leastDay];
    
    for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
    {
        for (int day = 0; day < NUM_DAYS; day++)
        {
            if (table[monkey][day] < leastFood)
            {
                leastFood = table[monkey][day];
                leastDay = day;
                leastMonkey = monkey;
            }
        }
        cout<< "On day " << leastDay << " Monkey " << leastMonkey << " ate the least food, " << leastFood << " pounds.\n" ;
    }
//*************************************************************//
// this function finds the highest amount eaten by the monkeys  *
//*************************************************************//

int findHighest(int table[][NUM_DAYS])
{
    int mostFood;
    int mostMonkey = 0;
    int mostDay = 0;
    int monkey = 0;
    mostFood = table[mostMonkey][mostDay];
    
    
    for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
    {
        for (int day = 0; day < NUM_DAYS; day++)
        {
            if (table[monkey][day] > mostFood)
            {
                mostFood = table[monkey][day];
                mostDay = day;
                mostMonkey = monkey;
            }
        }
        cout<< "On day " << mostDay << " Monkey " << mostMonkey << " ate the most food, " << mostFood << " pounds.\n" ;
        }
    
    }

}
Check your code for missing or misplaced braces and for functions that should be returning values but aren't.

Line 110: You're missing a } to terminate the function.

Line 136: You have an extraneous }

Line 111: findLowest must return a value.

Line 139: findHighest must return a value.


Thank you! I now have this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//  MonkeyLab_Kingsbury
//
//  Created by Caroline on 10/21/16.






#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
double average = 0;
void printContents(string monkeyNames[NUM_MONKEYS],int table[][NUM_DAYS]);
void rowSum(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS]);
void findLowest(int table[][NUM_DAYS]);
void findHighest(int table[][NUM_DAYS]);

//************************************************************//
// this function tracks the eating habits of 3 baby monkeys  *
//************************************************************//

int main()
{
    
    string monkeyNames[NUM_MONKEYS] = { "Curly", "Larry", "Moe" };
    
    int table[NUM_MONKEYS][NUM_DAYS] = { { 45,33,55,66,77,88,100 },
        { 88,77,66,55,44,33,22 },
        { 44,55,11,66,77,88,99 }
    };
    
    printContents(monkeyNames,table);
    rowSum(monkeyNames,table);
    
    findLowest(table);
    findHighest(table);
    
}
//************************************************************//
// this function prints the total food eaten by the monkeys  *
//************************************************************//
void printContents(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS])
{
    cout << "Name \t\tDay 1\tDay 2\tDay 3\tDay 4\tDay 5\tDay 6\tDay 7   " << endl;
    cout << "________________________________________________________________\n";
    for (int r = 0; r < NUM_MONKEYS; r++)
    {
        cout << monkeyNames[r];
        for (int c = 0; c < NUM_DAYS; c++)
        {
            cout << "\t\t";
            cout << table[r][c];
        }
        cout << endl;
    }
    cout << endl;
}

//*************************************************************//
// this function prints the sums of the rows for each monkey   *
//*************************************************************//
void rowSum(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS])
{
    cout<<"Name \tAverage daily intake in pounds \n";
    int totalRow=0;
    
    for(int r=0;r<NUM_MONKEYS;r++)
    {
        for(int c=0;c<NUM_DAYS;c++)
            
            totalRow=totalRow + table[r][c];
        
        cout<< monkeyNames[r] <<"\t"<< setw (1)<<(totalRow/NUM_DAYS) <<endl;
    }
    totalRow = 0;
}

//*************************************************************//
// this function finds the lowest amount eaten by the monkeys  *
//*************************************************************//

void findLowest(int table[][NUM_DAYS])
{
    int leastFood;
    int leastMonkey = 0;
    int leastDay = 0;
    int monkey = 0;
    leastFood = table[leastMonkey][leastDay];
    
    for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
    {
        for (int day = 0; day < NUM_DAYS; day++)
        {
            if (table[monkey][day] < leastFood)
            {
                leastFood = table[monkey][day];
                leastDay = day;
                leastMonkey = monkey;
            }
        }
        cout<< "On day " << leastDay + 1 << " Monkey " << leastMonkey << " ate the least food, " << leastFood << " pounds.\n" ;
        }
    }
//*************************************************************//
// this function finds the highest amount eaten by the monkeys  *
//*************************************************************//

void findHighest(int table[][NUM_DAYS])
    {
    int mostFood;
    int mostMonkey = 0;
    int mostDay = 0;
    int monkey = 0;
    mostFood = table[mostMonkey][mostDay];
    
    
    for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
    {
        for (int day = 0; day < NUM_DAYS; day++)
        {
            if (table[monkey][day] > mostFood)
            {
                mostFood = table[monkey][day];
                mostDay = day;
                mostMonkey = monkey;
            }
        }
        cout<< "\nOn day " << mostDay + 1 << ", Monkey " << mostMonkey << " ate the most food, " << mostFood << " pounds.\n" ;
    }
    }


But, my calculations are wrong, I'm not sure how to get the numbers I need.

This is my output:

1
2
3
4
5
6
7
8
9
10
11
12
13
Name 		Day 1	Day 2	Day 3	Day 4	Day 5	Day 6	Day 7   
________________________________________________________________
Curly		45		33		55		66		77		88		100
Larry		88		77		66		55		44		33		22
Moe		44		55		11		66		77		88		99

Name 	Average daily intake in pounds 
Curly	66
Larry	121
Moe	184
On day 2 Monkey 0 ate the least food, 33 pounds.
On day 7 Monkey 1 ate the least food, 22 pounds.
On day 3 Monkey 2 ate the least food, 11 pounds.


it's not even printing out my findHighest function, or properly printing out my findLowest or average intake!
Actually I realized that my lowest value was printing three times because I had it in the loop,
my output is now as follows:
1
2
3
4
5
6
7
8
9
10
11
12
Name 		Day 1	Day 2	Day 3	Day 4	Day 5	Day 6	Day 7   
________________________________________________________________
Curly		45		33		55		66		77		88		100
Larry		88		77		66		55		44		33		22
Moe		44		55		11		66		77		88		99

Name 	Average daily intake in pounds 
Curly	 66
Larry	121
Moe	184
On day 3 Monkey 3 ate the least food, 11 pounds.
(lldb) 

I bolded the sections that still elude me: my findHighest function is MIA and my averages are not printing the correct value.
It looks like your averages are adding up. Curly's average is 66 + Larry's average of 55 equals 121 then you add Moe's average of 62 which equals 184.

This is the output I get (after moving the print statement out of the loop).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Name            Day 1   Day 2   Day 3   Day 4   Day 5   Day 6   Day 7   
________________________________________________________________
Curly           45              33              55              66              77              88              100
Larry           88              77              66              55              44              33              22
Moe             44              55              11              66              77              88              99

Name    Average daily intake in pounds 
Curly   66
Larry   121
Moe     184
On day 2 Monkey 0 ate the least food, 33 pounds.
On day 7 Monkey 1 ate the least food, 22 pounds.
On day 3 Monkey 2 ate the least food, 11 pounds.

On day 7, Monkey 0 ate the most food, 100 pounds.
Last edited on
Topic archived. No new replies allowed.