1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Stolb23 [73]
3 years ago
14

Given an array temps of double s, containing temperature data, compute the average temperature. Store the average in a variable

called avgTemp . Besides temps and avgTemp , you may use only two other variables -- an int variable k and a double variable named total , which have been declared.Suppose the the temps array had just four elements: 5.4, 8.0, 2.0, and 4.6.Then the value of avgTemp that you would compute would be 5.0, because that is the average of the above four numbers.
Computers and Technology
1 answer:
Ket [755]3 years ago
6 0

Answer:

#include <iostream>

using namespace std;

// average function

void average(double arr[], int n) {

double total = 0;

double avgTemp;

for (int i = 0; i < n; i++)

{

 // find temperatures total

 total = total + arr[i];

}

// find average

avgTemp = total / n;

cout << "\nAverage Temperature = " << avgTemp << endl;

}

// print temps[] array

void printArray(double arr[], int n) {

for (int i = 0; i < n; i++)

{

 cout << arr[i] << "   ";

}

}

int main() {

int const k = 5;

double temps[k];

// temperature value

double tempValue;  

// Enter 5 temperatures of your choice

for (int i = 0; i < k; i++)

{

 cout << "Enter Temperature value " << i+1 << ": ";

 cin >> tempValue;

 temps[i] = tempValue;

}

// Function call to print temps[] array

printArray(temps, k);  

// Function call to print average of given teperatures

average(temps, k);        

return 0;

}

Explanation:

• Inside main(), int constant k is created to set the maximum size of array temps[].

• tempValue of  type double takes value at a given index of our temps[] array.

• the for loop inside main() is used to get tempValue from the user and store those values in our array temps[].

• after that printArray() function is called. to pass an array to a function it requires to perimeters 1) name of the array which is temps in our case. 2) maximum number of the index which is  k.

• note the syntax of void average(double arr[], int n). Since we are passing an array to the function so its formal parameters would be arr[] and an int n which specifies the maximum size of our array temps[].

You might be interested in
Given the variables costOfBusRental and maxBusRiders of type int , write an expression corresponding to the cost per rider (assu
Liono4ka [1.6K]

Answer:

       int costOfBusRental;

       int maxBusRiders;

       int costPerRider;

       costPerRider = costOfBusRental/maxBusRiders;

Explanation:

The costPerRider is the total cost of renting the bus (costofBusRental) divided by all the bus users (maxBusRiders). So we declare the three variables to be of type int as required by the question.

7 0
4 years ago
What is the difference between a learner’s license and an operator’s license?
SpyIntel [72]
I think a learners license is when your still in the process in getting a operator's license. A operator's license is that you are certified
4 0
3 years ago
Read 2 more answers
what sequence of tabs and buttons should hema select to include the current date on the pages printed with the speaker notes
SVEN [57.7K]
What sequence of tabs and buttons should Hema select to include the current date on the pages printed with the speaker notes?

Insert tab → Header & Footer → Notes and Handouts → Date and time → Update automatically
View → Header & Footer → Notes and Handouts → Date and time → Fixed
Insert → Notes and Handouts → Header & Footer → Date and time → Update automatically
View → Notes and Handouts → Header & Footer → Date and time → Fixed

Hope this helps.
8 0
3 years ago
Read 2 more answers
One hallmark of good strategic design is supporting a variety of gameplay styles and different ways to achieve victory.
Nonamiya [84]
It creates the illusion of creating a original path, so its true
3 0
4 years ago
Insurance can help you:
Scorpion4ik [409]
Hello,

Here is your answer:

The proper answer to this question is that insurance can help you..."recover something that was damaged or loss." For example if your vehicle gets damage insurance helps you fix it or if your home gets robbed insurance will help you get your things back!

If you need anymore help feel free to ask me!

Hope this helps!
6 0
4 years ago
Other questions:
  • A(n application system is the master controller for all the activities that take place within a computer system. _______________
    15·1 answer
  • What are the advantages of a peer-to-peer network? Select all that apply.
    15·1 answer
  • Jordan has been asked to help his company find a way to allow all the workers to log on to computers securely but without using
    6·1 answer
  • Fazer um programa em C++ que contenha 3 funções sendo:
    11·1 answer
  • How can you exaggerate the height of a jump in a photograph
    10·1 answer
  • CIST 1122 Project 2 Instructions
    11·1 answer
  • File Letter Counter
    14·1 answer
  • Scanning low allows you to locate __________ before you hit them
    13·1 answer
  • Which option is available when reviewing changes and using the Accept command in the Compare group?
    10·2 answers
  • David bought 5.2 pounds of oranges for $1.20 per pound . how much did david spend ..............................................
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!