### 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.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112`` ``````#include #include #include #include #include #include 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"<=allPokemon[greatest].HP) greatest=s; cout<<"The largest HP is "<< allPokemon[greatest].FirstInitial<<" with "<=allPokemon[greatest].Attack) greatest=a; cout<<"The largest attack is "<=allPokemon[greatest].Defense) greatest=d; cout<<"The largest Defense is "<< allPokemon[greatest].FirstInitial<<" with "<=allPokemon[greatest].SpAttack) greatest=f; cout<<"The largest SpAttack is "<=allPokemon[greatest].SpDefense) greatest=g; cout<<"The largest SpDefense is "<< allPokemon[greatest].FirstInitial<<" with "<=allPokemon[greatest].Speed) greatest=h; cout<<"The largest Speed is "<
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:

 ``12345678910`` ``````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:
 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````#include 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<: "; 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.