HippoEug HippoEug - 22 days ago 21
C++ Question

C++ requires a type specifier for all declarations

I am getting the error "C++ requires a type specifier for all declarations" on my "const MAX = 10;" line.

Here is my code:

//A program that adds up the maximum of 10 numbers ( 1,2,3,4,5,6,7,8,9,10 )


#include <iostream>
#include <cmath>
using namespace std;
const MAX = 10; //the error is here!

int main()
{
int sum, num;
sum = 0;
num = 1;

do
{
sum = sum + num;
num++;
}

while (num <= MAX);
{
cout << "Sum = ";
}
return 0;
}

Answer

As the error says, C++ requires a type specifier for the declaration. For instance, change const MAX = 10; to const int MAX = 10;.

Comments