I get an error when i try to compile this code. It says it has undeclared identifier.
"Main.cpp(13): error C2065: 'sum' : undeclared identifier"
I'm new to C++ and I don't see what the problem could be so any help would be appreciated.
# include <iostream>
using namespace std;
int main ()
{
double num1, num2, num3, avg;
num1 = 75.35;
num2 = -35.56;
num3 = 15.76;
sum = num1 + num2 + num3;
avg = sum/3;
cout << "Number 1 is" << num1 << endl;
cout << "Number 2 is" << num2 << endl;
cout << "Number 3 is" << num3 << endl;
cout << "Sum is" << sum << endl;
cout << "Average is" << avg << endl;
return 0;
}
Last edited on