string read_string(string prompt)
int read_integer(string prompt)
line = read_string(prompt);
return convert_to_integer(line);
* @brief Calculate the total length of all the names in the array
* @param names the array of names
* @param size the number of names in the array
* @return int with the total length of all the names
int total_length(string names[], int size)
// Start the result at 0 - if there are no names the total length is 0
// for each element in the array
for(int i = 0; i < size; i++)
// Add its length to the result
result += length_of(name);
// Return the total length
// Declare a constant for the size of the array
// Declare an array of three strings
// The array is called names
// Create a variable to store the index of the array
// This can be used to control the loops below
// Assign values to the elements within the array
// Start i at the first index - index 0
while ( i < SIZE ) // loop while i is less than the number of elements
// Store in the i-th element of the array
// i changes each loop - so this will store in names[0], names[1], ...
names[i] = read_string("Enter a name: ");
i = i + 1; // increment i... could be written as i++
// Access elements in the array to write out names entered
// Use a for loop to combine the loop control
// - i is initialised to 0
// - the loop continues while i is less than SIZE
// - i is incremented each loop (at the end)
for(i = 0; i < SIZE; i++)
// Use the total_length function to calculate the total length of all the names
write_line("Total length of all names: " + to_string(total_length(names, SIZE)));