Anaryl

Loop array challenge

Mar 11th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. // Loops and Arrays Challenge Rohan Kirkpatrick RGI Internationale
  2. /* •CHALLENGE: ◦Create a program that declares an array of 5 five integer values. These values will represent the health of 5 characters.
  3. ◦Initialise the values all to 100. Your program is to ask the user to enter a number (0 to 4) to select a character that is to be attacked by a monster.
  4. ◦Each attack deals 40 damage per attack. If a player's health gets below 0 they should not be able to be attacked.
  5. ◦Your program should simulate 5 attacks. After the attacks have finished, output the parties' remaining health to the console.
  6.  
  7. •CHALLENGE: ◦Have your program make use of arrays being passed into functions.
  8.  
  9. •CHALLENGE: ◦Research random number generation and modify your program so that random damage is dealt each attack.
  10.  
  11. */
  12.  
  13.  
  14. #include <iostream>
  15.  
  16. using namespace std;
  17.  
  18. const int SIZE_OF_ARRAY = 6;
  19.  
  20.  
  21.  
  22.  
  23. int main(int argc, char* argv[])
  24. {
  25. int charHealthArray[SIZE_OF_ARRAY];
  26. int charHeathArray[SIZE_OF_ARRAY] = {100,100,100,100,100};
  27.  
  28. int counter = 0;
  29.  
  30. int i;
  31.  
  32. int monster = 100;
  33. cout << "Please select between 0 - 4 for your character";
  34. cin >> i;
  35.  
  36.  
  37.  
  38. while ( counter < SIZE_OF_ARRAY);
  39. {
  40. for (int i = 0; i < SIZE_OF_ARRAY;) i++;
  41. counter++;
  42. }
  43. charHealthArray[counter];
  44.  
  45. do
  46. {
  47. counter - 40;
  48. cout << "A Monster attacked" << counter << endl;
  49. cout << "Do you run or fight, you have" << counter << "HP left" << endl;
  50. monster - 40;
  51. counter - 40;
  52. cout << "The monster has fought back";
  53. cout << "you have" << counter << "hp";
  54. }
  55. while (counter > 0);
  56.  
  57.  
  58. system ("pause");
  59.  
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment