Small Steps I — Creating with Text and Numbers
Keeping several values together
Change the third score to 90 and print it.
What you will learn
An array is an ordered collection of values of the same type. Small's Array<int> is a type that holds several integers.
Try it
Example · example.cpp
void small_main()
{
Array<int> scores = {80, 95, 70};
print(scores[0]);
scores[1] = 100;
print(scores[1]);
}
One value in an array is an element; its position number is an index. Like string positions, indices start at 0. With three elements, valid indices are 0, 1, and 2. Brackets let you read or change a value.
Expected output:
80
100
Exercise
Change the third score to 90 and print it.
Exercise starter · exercise_starter.cpp
void small_main()
{
Array<int> scores = {80, 95, 70};
print(scores[0]);
scores[1] = 100;
print(scores[1]);
}
Hint
Change the parts of the example that you need.
show solution
void small_main()
{
Array<int> scores = {80, 95, 70};
scores[2] = 90;
print(scores[2]);
}