Average of 3 numbers

Using my code the average is always coming up weird. When I commented out the average to see each value, the numbers were coming up as very weird.

For example: If I entered "4 5 6"
num1=4
num2=0
num3=2.07358e-317

How do I fix this, what is wrong with my code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 #include<iostream>
#include<math.h>

using namespace std;

int main()
{
    double dblnum1;
    double dblnum2;
    double dblnum3;
    double average;
    cout <<"Enter your numbers separated by a space. ";
    cin >> dblnum1, dblnum2, dblnum3;
    average= (dblnum1+dblnum2+dblnum3)/3;
    /*cout << "Your numbers are "<< dblnum1 << dblnum2 << dblnum3 <<endl;
    cout << "The average = " << average <<endl;*/
    cout << "Your first number is " << dblnum1<<endl;
    cout << "Your second number is " << dblnum2<<endl;
    cout << "Your third number is " << dblnum3<<endl;
    return 0;
}
cin >> dblnum1, dblnum2, dblnum3;

That's not how it's done. Change it to -

cin >> dblnum1 >> dblnum2 >> dblnum3;
Topic archived. No new replies allowed.