Program instructions: 1. The Array is read in to the Array(s) by function IN_TMP
ID: 3622235 • Letter: P
Question
Program instructions:1. The Array is read in to the Array(s) by function IN_TMP(), pass the array variable by address to the function
2. The values are output by function OUT_TMP(), pass the array variable by address to the function
3. Create a separate function AVG_TMP() that will return the average temperatures of the week (will be called twice once for high and once for low) to the main() function to be printed out, [you will need to pass the array variables to the function]
I am using Dev C++ so make sure the program both compiles and runs. If it does and it is correct, a Lifesaver will be given.
Explanation / Answer
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
//function definitions
void IN_TMP(double temp[],int size) //function to input temperatures
{
int i;
for( i=0; i<size; i++)
{
cout << "enter temperature value" << " "<< (i+1) << ":";
cin>>temp[i];
}
}
void OUT_TMP(double temp[],int size) //function to output temperatures
{
cout << endl;
cout<<"Temperatures are:";
int i;
for(i=0; i<size; i++)
cout<<temp[i] << " ";
cout<<endl;
}
double AVG_TMP(double temp[],int size) //function to calculate average of temperatures
{
double sum=0;
int i;
for(i=0; i<size; i++)
sum+= temp[i];
return (sum/size);
}
int main() // start of main
{
double temperatures[10];
IN_TMP(temperatures,7);
OUT_TMP(temperatures,7);
double avg=AVG_TMP(temperatures,7);
cout<<"Average temperature is :" << avg << endl;
getch();
return 0;
}//end main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.