how could i make this work, and why doesnt it

how can i initialize variables stored in anobject array...or whatever you call what im trying to do?

this is my goal...

Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.




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
#include <iostream>
#include <string>

using namespace std;

class fatty{
public:
int name;
int pancake;

};
int main()

{

    int highcake = 0;
    string namebox;
    fatty fat [8];
    for (int q =0; q > 8; q++)
    {
        fatty fat [q];
        cout << "enter fatties name "<<endl;
        cin >> fat[q].name;
        cout << "how many pancakes has the fat bastard eaten?" << endl;
        cin >> fat[q].pancake;
        if (fat [q]pancake < highcake)
         {
         highcake = fat[q].pancake;
         namebox = fat [q].name;
        }
    }

cout << "fat bastard called " << namebox << "ate the most cake ( " << highcake << " pancakes )" <<endl;



return 0;
}
Delete line 21. It's hiding the array on line 18.
Now we have 3 threads for the same topic.
i know i know well now i do :/ still same result different hopeless code
could someone show me the answer...put me out of my (pseudo) misery?
Your class is wrong, it tries to use an integer to store the name. Try this:
1
2
3
4
5
class fatty{
public:
    string name;
    int pancake;
};


The comparison code to find the biggest might look like this:

1
2
3
4
        if (fat[q].pancake > fat[highcake].pancake)
        {
            highcake = q;
        }


And the final result displayed like this:

 
    cout << "fat bastard called " << fat[highcake].name << " ate the most cake ( " << fat[highcake].pancake << " pancakes )" <<endl;


That's almost the entire answer. Just needs putting into practice now.
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
#include <iostream>
#include <string>

using namespace std;

class fatty{
public:
string name;
int pancake;

};
int main()

{

    int highcake = 0;
    string namebox;
    fatty fat [8];
    for (int q =0; q < 8; q++)
    {
        fatty fat[q];
        cout << "enter fatties name "<<endl;
        cin >> fat[q].name;
        cout << "how many pancakes has the fat bastard eaten?" << endl;
        cin >> fat[q].pancake;
       if (fat[q].pancake > fat[highcake].pancake)
        {
            highcake = q;
        }
    }

    cout << "fat bastard called " << fat[highcake].name << " ate the most cake ( " << fat[highcake].pancake << " pancakes )" <<endl;




return 0;
}



it looks good...unfortunatley it crashes...i just thought maybe i should add the names first
it doesnt like this either...although it cheks out through build it crashes too

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
#include <iostream>
#include <string>

using namespace std;

class fatty{
public:
string name;
int pancake;

};
int main()

{

    int highcake = 0;
    string namebox;
    fatty fat [8];
    fat[0].name = "elvis";
    fat [1].name = "yo momma";
    fat [2].name = "dr strangelove";
    fat [3].name = "bubbah";
    fat [4].name = "kobiyoshi";
    fat [5].name = "santa";
    fat [6].name = "cartman";
    fat [7].name = "kublah kahn";
    
    for (int q =0; q < 8; q++)
    {
        fatty fat[q];
        cout << "how many pancakes has "<< fat[q].name <<  "  eaten?" << endl;
        cin >> fat[q].pancake;
       if (fat[q].pancake > fat[highcake].pancake)
        {
            highcake = q;
        }
    }

    cout << "fat bastard called " << fat[highcake].name << " ate the most cake ( " << fat[highcake].pancake << " pancakes )" <<endl;




return 0;
}
I DID IT XD

thanks everyone...guess i didnt do it all by myself...the thing making it crash in my last code crash was line 30! i didnt need to declare it and so it confused everything :D

one last thing though line 39 how does this work??

( " << fat[highcake].pancake << " pancakes )


i repeated this reply on my last post too will check em both....

what project now too??
Topic archived. No new replies allowed.