-
using functions...
Can anyone help me figure out why this isn't compileing, i basiclly want the program to tell me if the array is all even. but its not compiling.
I keep getting these compiling errors
12 C:\Dev-Cpp\main.cpp expected `)' before '!' token
16 C:\Dev-Cpp\main.cpp expected primary-expression before "else"
16 C:\Dev-Cpp\main.cpp expected `;' before "else"
18 C:\Dev-Cpp\main.cpp expected primary-expression before "int"
18 C:\Dev-Cpp\main.cpp expected `;' before "int"
24 C:\Dev-Cpp\main.cpp expected `}' at end of input
Code:
#include <iostream>
using namespace std;
bool All_Even()
{
int x;
int a_array[5]= {4,2,4,5,6};
while(x =0 < 5)
{
if (a_array[x]!% = 0)
x++;
return false;
}
else return true;
int main()
{
cout<<"this program is all even" << All_even;
system("PAUSE");
return 0;
}
-
!% is not a valid token.
Note that (x=0 < 5) does not do what you want to do -- you're trying to do a for loop, so use a for loop.
You're also missing an open curly brace and a close curly brace.
Also: All_even does not exist, since you created a function called All_Even. Had you spelled it correctly, the function would still not be called, since functions are not called unless they are followed by parentheses.
-
if you had proper indentation - you would see the problem with braces
Code:
while(x =0 < 5)
{
if (a_array[x]!% = 0)
x++;
return false;
}
else return true; // else without if