Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Introduction to Arrays An array is a variable capable of storing multiple val

ID: 3607059 • Letter: 3

Question

3. Introduction to Arrays An array is a variable capable of storing multiple values. When we declare an array we tell the compiler how many values we want the array to hold. We also tell the compiler what type of values the array can store. All of the values in an array must be of the same type. For this program, we will be counting how many zombies are in the eight hordes approaching your house, and then calculating the total you w be facing. Here is a declaration of an array called hordelist that wll be used to store 8 ntegers const ine SI2E-8 ane bordeliat [SIZE]; //deelar ist srrwy that com tec. 0 vslae If we wish to fill the array hordelist with the integers typed from the keyboard you can use a for loop. Here is a for loop that will allow you to enter 8 values from the keyboard and store them in the array hordelist. Notice that we have used the variable i as an index for array horde1ist It might be easier for our user to keep up with different values that need to be entered if we display something more helpful than "Enter the number of zombies the next horde:. Since users typically number items in a list starting from 1, we will say Enter the number of zombies in horde 1: when asking for horde1ist [0) Enter the number of zombies in horde 2: when asking for hordelist[11. and so forth. Here is the improved version of the loop: for ( 0, i

Explanation / Answer

//Here is the solution for Lab9.c

//Save the file name as Lab9.c

#include <iostream>

using namespace std;

int main()

{

const int SIZE = 8; //size of hordes

int hordeList[SIZE]; //horde array that can store 8 values

int i;

for(i = 0; i< SIZE; i++){

cout<<"Enter the number of Zombies in horde "<< i+1<<": ";

cin>>hordeList[i];

}

int totalZombies = 0;

for(int i = SIZE; i > 0; i--){

cout<<"Horde #"<< i <<": " << hordeList[i - 1]<<endl;

totalZombies += hordeList[i -1];

}

cout<<"The total no of Zombies is "<<totalZombies <<".";

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote