passing info from function to function

Ok I want to use a function to perform some calculations and then pass that info to another function to display.given my code so far I cant seem to figure a way to do this (pass from function to function) also I want to display a filled array line by line and i cant seem to do this either..please any help would be appreciated
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
void get_hrTmps (int hr_tmps[],int tmp_num); //function for user input
double ComputeAverageTemp(int hr_tmps[],int tmp_num);//add the individual array element and then avereage them
void DisplayTemperatures(int hr_tmps[], int temp_num);

#include <iostream>// for cin,cout
using namespace std;

int main ()
{
	const int tmp_num = 24 ;//constant for 24 hours
	int hr_tmps[tmp_num];//array to hold the hours


	get_hrTmps(hr_tmps,tmp_num);//function call fdor input

	ComputeAverageTemp(hr_tmps,tmp_num);//function call to add the individual array element and then avereage them
	
	DisplayTemperatures( hr_tmps,  tmp_num);


	return 0;
}

void get_hrTmps (int hr_tmps[],int tmp_num)//input function
{
    cout<<"please enter a temp for each hour of the day\n please use only #'s between -15 and a 130\n";

    for (int x=0; x<tmp_num; x++)

	cin>>hr_tmps[x];

}


double ComputeAverageTemp(int hr_tmps[],int tmp_num)//calculation function
{
	int total=0;
	double average;

	for (int x=0;x<tmp_num;x++)

		total=total+hr_tmps[x];
	average=total/24;
	return average;
}


void DisplayTemperatures(int hr_tmps[], int tmp_num )//output function
{
	
	for (int x=0;x<tmp_num;x++)

		cout<<hr_tmps[0-23]<<endl;
}





Last edited on
anyone?
1
2
3
4
5
6
7
8
9
10
11
double ComputeAverageTemp(int hr_tmps[],int tmp_num)//calculation function
{
    double total =0;//int total=0; //should really be a double for accuracy
    double average;

    for (int x=0;x<tmp_num;x++)

        total=total+hr_tmps[x];
    average=total/24;
    return average;
}



1
2
3
4
5
6
7
8
void DisplayTemperatures(int hr_tmps[], int tmp_num )//output function
{
    
    for (int x=0;x<tmp_num;x++)

        //cout<<hr_tmps[0-23]<<endl; //****Error
        cout<<hr_tmps[x]<<endl;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{   
    
    const int tmp_num = 24 ;//constant for 24 hours
    int hr_tmps[tmp_num];//array to hold the hours


    get_hrTmps(hr_tmps,tmp_num);//function call fdor input

    //*****The compute function returns a value
    //**If you want to use it here you need to assign it to a variable
    double average;
    average = ComputeAverageTemp(hr_tmps,tmp_num);//function call to add the individual array element and then avereage them
    
    DisplayTemperatures( hr_tmps,  tmp_num);

    return 0;
}



Read up on functions
Topic archived. No new replies allowed.