Array: Mathematics and Family Members

Only available on StudyMode
  • Download(s) : 79
  • Published : August 18, 2013
Open Document
Text Preview
This program will let the user enter all the names of their family members, the ages of those family members, and their state of residence. The program will display the average age of all family members input, and also display the names of any family members that live in Texas. We will create three separate arrays; one for the names of the family members, another for their ages, and the third will be for their state of residence. We'll first ask the user to enter the number of family members he has (we will limit this to a max of 25); this will allow us to determine how large of arrays we will need to create to store the data. We'll call this variable Size. After inputting all names, ages, and states of residence the data will all be stored within the arrays. The program will identify those family members who reside in Texas, and also display their names on the screen. This will be done by creating a loop that will review all the entries from the names and residencies arrays, compare the state to the string "Texas," and print that corresponding name. The average age will be calculated by also looping through the values in the age array, calculating the collective sum, then (as stated earlier) dividing by Size.

Necessary Calculations
The variable AvgAge (declared as Float) will be used in order to calculate the average age. A loop will go through each value of the Ages array, keep a running total sum, then divide that total by the variable Size to get the average age. //NOTE: I use Float instead of Integer because there is a possibility of losing a trailing decimal if //numerical data is calculated as an Integer. AvgAve = sum of all ages Size

So for example, if 13 family members are entered and the sum of all their ages is 169, AvgAge would equate to 13.

What is the required output?
Output to the screen will include:
The average age of all the user's input; and
The names of family members that reside in Texas.

What is the...
tracking img