Type 'double' unexpected error.

I tried to compile this but it wouldn't let me because of this error. I want the average to be the total of the num1 and num2 Any ideas?

#include <iostream>
using namespace std;


int main()

{

int num1,
num2,
double average;


cout << "Enter two integers separated by one or more spaces: ";
cin >> num1, num2;

average = (num1 + num2);

cout << "\nThe average of these 2 numbers is " << average << "endl";

return 0;

}
For every cin you need a separate extraction operator (>>).

so:

cin >> num1 >> num2
The statement where you declare num1 and num2 should end with a semicolon instead of a comma.

You can't use the comma operator if you want to input two values from cin using >>. One way to fix this is to replace the comma with another >>.
Last edited on
It works!! Thanks so much you guys!
Topic archived. No new replies allowed.