Thread: using functions...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    10

    Question 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;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    !&#37; 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.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if you had proper indentation - you would see the problem with braces
    Code:
    while(x =0 < 5)
    {
        if (a_array[x]!&#37; = 0)
            x++;
        return false;
    }
    else return true; // else without if
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM