Pokemon code help

The point of this program is to make a chart of the pokemon stats for the amount of pokemons i have listed. I got it to do this part just fine, however the next part is where i am having trouble. I need it to compare each set of data like all the stats in the attack and choose the highest one and display it. I assumed that i could do this by comparing it to itself and the one that is greatest than or equal to will print. Unfortunately this is not working and im not quite sure what to do. Please give me some guidance. I am also new too this as you can probably tell from the code. Thanks so much!

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
 #include<iostream>
#include<cmath>
#include<iomanip>
#include <cstdlib>
#include <ctime>
#include <stdio.h>


using namespace std;
struct Pokemon{
    char FirstInitial;
    int HP;
    int Attack;
    int Defense;
    int SpAttack;
    int SpDefense;
    int Speed     ;
};



int main() {
   int greatest=0;
    Pokemon allPokemon[6];

    allPokemon[0]={'C',39,52,43,60,50,65}; // Charmander
    allPokemon[1]={'P',40,45,40,35,35,56}; // Pidgey
    allPokemon[2]={'T',50,64,64,44,48,43}; // Totodile
    allPokemon[3]={'H',45,50,45,115,55,95};// Haunter
    allPokemon[4]={'A',25,20,15,105,56,90};//Abra
    allPokemon[5]={'M',20,10,55,15,20,80}; //Magikarp

    cout << setw(2) << "FI" << setw(3) << "HP" << setw(4) << "ATK" << setw(4) <<"DEF"
         << setw(6) <<"SpAtk"<<setw(6) << "SpDef" <<setw(4) <<"SPD" << endl;
    cout << "-----------------------------"<<endl;

    for(int k=1; k<=6;k++)
        {
        cout << setw(2) << allPokemon[k].FirstInitial;
        cout << setw(3) << allPokemon[k].HP;
        cout << setw(3) << allPokemon[k].Attack;
        cout << setw(4) << allPokemon[k].Defense;
        cout << setw(4) << allPokemon[k].SpAttack;
        cout << setw(6) << allPokemon[k].SpDefense;
        cout << setw(6) << allPokemon[k].Speed;
        cout << setw(4) << endl;

    }
    for(int i=1; i<=6;i++)
        switch(i)
    {
            case 1:

                    for(int a=0; a<=5;a++)

                    if (allPokemon[a].Attack>=greatest)
                    greatest=a;
                cout<<"The largest attack is "<< allPokemon[greatest].Attack<<endl;
                break;

            case 2:
                for(int s=0; s<=5;s++)
                    if (allPokemon[s].HP>=greatest)
                        greatest=s;
                cout<<"The largest HP is "<< allPokemon[greatest].HP<<endl;
                break;
            case 3:
                for(int d=0; d<=5;d++)
                    if (allPokemon[d].Defense>=greatest)
                        greatest=d;
                cout<<"The largest Defense is "<< allPokemon[greatest].Defense<<endl;
                break;

            case 4:
                for(int f=0; f<=5;f++)
                    if (allPokemon[f].SpAttack>=greatest)
                        greatest=f;
                cout<<"The largest SpAttack is "<< allPokemon[greatest].SpAttack<<endl;
                break;

            case 5:
                for(int g=0; g<=5;g++)
                    if (allPokemon[g].SpDefense>=greatest)
                        greatest=g;
                cout<<"The largest SpDefense is "<< allPokemon[greatest].SpDefense<<endl;
                break;
            case 6:
                for(int h=0; h<=5;h++)
                    if (allPokemon[h].Speed>=greatest)
                        greatest=h;
                cout<<"The largest Speed is "<< allPokemon[greatest].Speed<<endl;
                break;


    }

    return 0;
}
Something like this, perhaps?
Note, this program uses <string> and <algorithm>.

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

const unsigned short num_pokemon = 6;
const unsigned short num_attributes = 6;

struct Pokemon {
	std::string name;
	unsigned short attributes[num_attributes];
	//store the different attributes in an array
	//hp, attack, defense, spAttack, spDefense, speed;
};

int main() {

	Pokemon pokemon[num_pokemon];

	pokemon[0] = { "Charmander", { 39, 52, 43, 60, 50, 65 } };
	pokemon[1] = { "Pidgey", { 40, 45, 40, 35, 35, 56 } };
	pokemon[2] = { "Totodile", { 50, 64, 64, 44, 48, 43 } };
	pokemon[3] = { "Haunter", { 45, 50, 45, 115, 55, 95 } };
	pokemon[4] = { "Abra", { 25, 20, 15, 105, 56, 90 } };
	pokemon[5] = { "Magikarp", { 20, 10, 55, 15, 20, 80 } };


	std::string attributeStrings[num_attributes] = { "health", "attack", "defense", "spAttack", "spDefense", "speed"};

	for (unsigned short i = 0; i < num_attributes; ++i) {
		//for each attribute...

		unsigned short currentAttribute[num_pokemon];
		//create a temporary array

		for (unsigned short j = 0; j < num_pokemon; ++j) {
			currentAttribute[j] = pokemon[j].attributes[i];
			//fill that array with the current attribute data from each pokemon
		}

		unsigned short index = std::distance(currentAttribute, std::max_element(currentAttribute, currentAttribute + num_pokemon));
		//std::max_element returns an iterator to the element in the array with the largest value.
		//Since the pokemon array is... an array (and not a vector or something), we can use std::distance to effectively convert the returned iterator to an index location to make it easier to work with.

		std::cout << "The largest " << attributeStrings[i] << "\tis " << pokemon[index].name << " with " << pokemon[index].attributes[i] << std::endl;
	}

	std::cin.get();
	return 0;
}
Thanks for the help! But i was wanting something using the headers i have. I have not yet learned that yet and this is a shool assighnment. Id like to learn what exactly i did wrong in the for loop....
Your way looks so much easier though, and it makes sence for the most part to me.
Topic archived. No new replies allowed.