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

Write this program in C++. Write a small program that fills an array of doubles

ID: 3767920 • Letter: W

Question

Write this program in C++. Write a small program that fills an array of doubles with user input, prints the doubles on the screen in a column, and adds up all the doubles in the array and prints the sum onto the screen. You must use at least 3 functions - Declare an array of doubles of size 20. - Ask the user how many doubles to enter <= 20. - Use a loop to read the doubles into the array from the user. - Use a loop to print the array onto the screen in a column. - Use a loop to add up all the items in the array and store the sum - print the sum onto the screen

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;

double arr[20];

void inp(){
  
for(int i = 0; i < 20; i++){
cout << "Enter number " << i+1 << " : ";
cin >> arr[i];
}

}

void out(){
for(int i = 0; i < 20; i++){
cout << "Value " << i+1 << " : " << arr[i] << endl;
}
}

void sum(){
double sum = 0;
for(int i = 0; i < 20; i++){
sum += arr[i];
}

cout << "The sum is: " << sum << endl;
}

int main(){
  

cout << "Enter 20 doubles: ";
//double sum = 0;

inp();
out();
sum();

return 0;
}