Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Loops and Arrays Challenge Rohan Kirkpatrick RGI Internationale
- /* •CHALLENGE: ◦Create a program that declares an array of 5 five integer values. These values will represent the health of 5 characters.
- ◦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.
- ◦Each attack deals 40 damage per attack. If a player's health gets below 0 they should not be able to be attacked.
- ◦Your program should simulate 5 attacks. After the attacks have finished, output the parties' remaining health to the console.
- •CHALLENGE: ◦Have your program make use of arrays being passed into functions.
- •CHALLENGE: ◦Research random number generation and modify your program so that random damage is dealt each attack.
- */
- #include <iostream>
- using namespace std;
- const int SIZE_OF_ARRAY = 6;
- int main(int argc, char* argv[])
- {
- int charHealthArray[SIZE_OF_ARRAY];
- int charHeathArray[SIZE_OF_ARRAY] = {100,100,100,100,100};
- int counter = 0;
- int i;
- int monster = 100;
- cout << "Please select between 0 - 4 for your character";
- cin >> i;
- while ( counter < SIZE_OF_ARRAY);
- {
- for (int i = 0; i < SIZE_OF_ARRAY;) i++;
- counter++;
- }
- charHealthArray[counter];
- do
- {
- counter - 40;
- cout << "A Monster attacked" << counter << endl;
- cout << "Do you run or fight, you have" << counter << "HP left" << endl;
- monster - 40;
- counter - 40;
- cout << "The monster has fought back";
- cout << "you have" << counter << "hp";
- }
- while (counter > 0);
- system ("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment