Thread: Codeblocks and logical operators

  1. #1
    Registered User
    Join Date
    Nov 2008

    Codeblocks and logical operators

    Hey all, I am writing a program that computes prime numbers. I get the following error message when I try to build.
    |24|error: expected identifier before '(' token|
    I've tried the other logical operators (||, !) but they generate the same error. If I delete the logical operator and the 2nd part of the condition the code works perfectly fine. Please note I know that my algorithm is probably flawed but I want to figure those flaws out myself so please do not correct my algorithm.
    #include <iostream>
    #include "LargeNumber.h"
    #include <stdexcept>
    using namespace std;
    int value;
    int a_prime_number;
    int divider;
    int analyzer;
    int stop_value;
    int main()
        cout << "What number would you like to start with?(Must be greater than 1)\n";
        cin >> value;
        cout << "What number would you like to stop at?(must be larger than start value)\n";
        cin >> stop_value;
        cout << "Starting calculations, this will take a while\n";
        while ( value < stop_value )
            divider = 2;
            analyzer = value % divider;
            if (0 == analyzer) && (value <= divider)
                cout << "## Debug message1\n";
            else if ( value <= divider )
                cout << "## Debug message2\n";
                a_prime_number = value;
                cout << a_prime_number << "\n";
                cout << "## Debug message4\n";
    cout << "Done\n";
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    Thanks in advance for any help

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > if (0 == analyzer) && (value <= divider)
    Needs ( ) around the whole thing.

    if ( condition )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    The larch
    Join Date
    May 2006
    And technically doesn't need brackets around subexpressions since operator == has higher precedence than && anyway (though you may use them for clarity).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed