Write a return function called averageFourTemperatures that accepts 4 integers in the parameter list, returns the average.

In the main function prompt the user for 4 temperatures and them in separate appropriately named variables.

Call the averageFourTemperatures, passing values and printing the returned average to the console.

While, I wouldn't normally do it this way, I tried to match what you were asking.

#include <iostream>

double display_temp(double temp1, double temp2, double temp3, double temp4);
double temp1 = 0;
double temp2 = 0;
double temp3 = 0;
double temp4 = 0;

void main()
{   
    std::cout << "Temperature 1: ";
    std::cin >> temp1;
    std::cout << "Temperature 2: ";
    std::cin >> temp2;
    std::cout << "Temperature 3: ";
    std::cin >> temp3;
    std::cout << "Temperature 4: ";
    std::cin >> temp4;
    std::cout << display_temp(temp1,temp2,temp3,temp4);
}

double display_temp(double temp1, double temp2, double temp3, double temp4)
{
double averageFourTemperatures = ((temp1 + temp2 + temp3 + temp4) / 4);
return averageFourTemperatures;
}

Temperature 1: 10.25
Temperature 2: 44.26
Temperature 3: 33.3
Temperature 4: 78
Average temperature: 41.4525

While I wouldn't normally write it this way, I tried to match what you were looking for.

#include <iostream>

double display_temp(double temp1, double temp2, double temp3, double temp4);
double temp1 = 0;
double temp2 = 0;
double temp3 = 0;
double temp4 = 0;

void main()
{   
    std::cout << "Temperature 1: ";
    std::cin >> temp1;
    std::cout << "Temperature 2: ";
    std::cin >> temp2;
    std::cout << "Temperature 3: ";
    std::cin >> temp3;
    std::cout << "Temperature 4: ";
    std::cin >> temp4;
    std::cout << display_temp(temp1,temp2,temp3,temp4);
}

double display_temp(double temp1, double temp2, double temp3, double temp4)
{
double averageFourTemperatures = ((temp1 + temp2 + temp3 + temp4) / 4);
return averageFourTemperatures;
}


/*
Temperature 1: 10.25
Temperature 2: 44.26
Temperature 3: 33.3
Temperature 4: 78
Average temperature: 41.4525
*/
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.