WSQ10

This program is created using arrays in order to store a maximum of numbers entered by the user.

After that, the stored numbers can be used to create a sum of them and the average of them as well. This works because we created a function that stored 5 numbers (array [5]) in order to be able to ask the user for 5 numbers to be stored.

here is the code with notes to be better understanded:

<iostream>

using namespace std;

 

int main(){

int array [5]; //declaring the array with a maximum of 5 values

 

for (int i=0; i<5; i++){ //the first loop will sotre the values from 0 to 4 (including 0)

  cout << “please give us a number: “;

  cin >> array [i]; // the program will read the values that the user enters until value # 4

 

}

for (int i=0; i<5; i++){ // the program will show the values that the user entered

  cout << array [ i ]<<endl;

}

int sum = 0;//fisrt variable to sum the values from the array

int average,sum1;

for (int i = 0; i < 5; ++i)// this loop will give the program all the values from the array in order to sum them

  sum+=array[i];// sums the values given by the array

average = sum/5; //gets average

cout<<” Average:”<<average;

 

 

return 0;

}

 

CC BY 4.0 WSQ10 by carlos green is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.