POkemon!

I am not sue how to add up he total of the individual pokemons stats from the array, and find the pokemon with the largest total stats.
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
#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     ;
};


void highpokemon (int)
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=0; k<=5;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 s=1; s<=5;s++)
                    if (allPokemon[s].HP>=allPokemon[greatest].HP)
                        greatest=s;
                cout<<"The largest HP is "<< allPokemon[greatest].FirstInitial<<" with "<<allPokemon[greatest].HP<<" HP."<<endl;
                greatest=0;
                break;



            case 2:
               for(int a=1; a<=5;a++)
                    if (allPokemon[a].Attack>=allPokemon[greatest].Attack)
                    greatest=a;
                cout<<"The largest attack is "<<allPokemon[greatest].FirstInitial <<" with "<<allPokemon[greatest].Attack<<" HP."<<endl;
                greatest=0;
                break;
            case 3:
                for(int d=1; d<=5;d++)
                    if (allPokemon[d].Defense>=allPokemon[greatest].Defense)
                        greatest=d;
                cout<<"The largest Defense is "<< allPokemon[greatest].FirstInitial<<" with "<<allPokemon[greatest].Defense<<" HP."<<endl;
                greatest=0;
                break;
            case 4:
                for(int f=1; f<=5;f++)
                    if (allPokemon[f].SpAttack>=allPokemon[greatest].SpAttack)
                        greatest=f;
                cout<<"The largest SpAttack is "<<allPokemon[greatest].FirstInitial <<" with "<<allPokemon[greatest].SpAttack<<" HP."<<endl;
               greatest=0;
                break;


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

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


    }

    return 0;
}



closed account (jvqpDjzh)
and find the pokemon with the largest total stats.
You have to define what you mean by this. For example, it could be the sum of all the characteristics, but could also be in another way!
Initialize a largest int variable, iterate through the stats you want to check, with each loop initialize another temp variable to 0, with this variable (the one local to the loop) add up the stats for the pokemon and compare it to the largest variable. If the temp variable is larger than the largest variable after all values have been added, then make largest = temp. Like this:

1
2
3
4
5
6
7
8
9
10
initialize largest variable to 0

for(iterate through array){
     initialize temp variable to 0
     add all values from current pokemon to temp
     if(temp is greater than largest){
          make largest equal temp
     }
}
closed account (j3Rz8vqX)
A possibility:
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>
using namespace std;

struct Pokemon{
    char FirstInitial;
    int HP;
    int Attack;
    int Defense;
    int SpAttack;
    int SpDefense;
    int Speed;
    int totalStats(){
        return (HP+Attack+Defense+SpAttack+SpDefense+Speed);
    }
};
int main()
{
    int greatestPokemon=0, greatestStats=0;
    Pokemon allPokemon[] =
    {
        {'C',39,52,43,60,50,65},    // Charmander
        {'P',40,45,40,35,35,56},    // Pidgey
        {'T',50,64,64,44,48,43},    // Totodile
        {'H',45,50,45,115,55,95},   // Haunter
        {'A',25,20,15,105,56,90},   // Abra
        {'M',20,10,55,15,20,80}     // Magikarp
    };
    for(int i=0;i<6;++i){
        if(allPokemon[i].totalStats()>greatestStats){
            greatestPokemon=i;
            greatestStats=allPokemon[i].totalStats();
        }
    }
    cout<<allPokemon[greatestPokemon].FirstInitial<<" has the greatest stats of: "<<greatestStats<<endl;
    cout<<"\nConsole Exit - Press <enter>: ";
    cin.get();
    return 0;
}
Oh i see....
I will try and get the program to run, with yours kitty. I will let you know if i am succesfull.
And thanks a bunch DPut!
Topic archived. No new replies allowed.