Getting function to return double

Hey guys so this is exactly what i'm suppose to do. Write a function named avg that has three int parameters and returns a double representing the average of those three integers. Then write a simple driver in main to test the function.

I just don't know what to do to return the double as right now it just truncates to an int. But this is what i got so far.
thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 #include<iostream>
#include<iomanip>
using namespace std;

/***********************************
*function: main
*description: 
*************************************/
//prototype
double avg(int, int, int);
int main ()

{
	double average= avg(30, 12 , 25);
	cout << average;
}

double avg(int num1, int num2, int num3)
{
	double average = (num1 + num2 + num3)/3;
	cout << average;
	return average;
}
closed account (48T7M4Gy)
delete line 21



double average = double((num1 + num2 + num3))/3
Last edited on
Whats wrong with the division?
closed account (48T7M4Gy)
The division is OK I misread what you wrote. My bad but the fix works :)
lol Thanks!!
Topic archived. No new replies allowed.