Results 1 to 5 of 5

Thread: compiler error in geany C++

  1. #1
    Join Date
    Sep 2013
    Beans
    4

    Question compiler error in geany C++

    so i am in the process of learning C++ and am reading a book on it, one of the programs it has you make is:

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    typedef unsigned short int SMALLNUMBER;
    
    
    int main()
    {
        SMALLNUMBER = 65535;
        cout << "small number:" << SMALLNUMBER << endl;
        SMALLNUMBER++;
        cout << "small number:" << SMALLNUMBER << endl;
        SMALLNUMBER++;
        cout << "small number:" << SMALLNUMBER << endl;
        return 0;
    }
    the code above is exactly how it appears in the book, but geany is giving me these errors:

    Code:
    g++ -Wall -c "exersize8.cpp" (in directory: /home/neo/Documents/c++/exercises)exersize8.cpp: In function ‘int main()’:
    exersize8.cpp:9:14: error: expected unqualified-id before ‘=’ token
    exersize8.cpp:10:41: error: expected primary-expression before ‘<<’ token
    exersize8.cpp:11:13: error: expected unqualified-id before ‘++’ token
    exersize8.cpp:12:41: error: expected primary-expression before ‘<<’ token
    exersize8.cpp:13:13: error: expected unqualified-id before ‘++’ token
    exersize8.cpp:14:41: error: expected primary-expression before ‘<<’ token
    Compilation failed.
    now i have no idea why these have popped up but some help would be great

  2. #2
    Join Date
    Apr 2012
    Beans
    6,188

    Re: compiler error in geany C++

    The typedef defines a type of variable, not an actual variable - think of the word 'SMALLNUMBER' as a synonym for 'unsigned short int'. To define a variable of that type you would then do something like

    Code:
    SMALLNUMBER mynumber = 65535;
    just as for any other simple type; and then use it like

    Code:
    cout << "small number: " << mynumber << endl;
    and so on

  3. #3
    Join Date
    Sep 2013
    Beans
    4

    Re: compiler error in geany C++

    Quote Originally Posted by steeldriver View Post
    The typedef defines a type of variable, not an actual variable - think of the word 'SMALLNUMBER' as a synonym for 'unsigned short int'. To define a variable of that type you would then do something like

    Code:
    SMALLNUMBER mynumber = 65535;
    just as for any other simple type; and then use it like

    Code:
    cout << "small number: " << mynumber << endl;
    and so on
    see but the last program had that typed exactly the same way as is here, i double checked it cause it was just added into the book at the point im on as is shown here:

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    typedef unsigned short int USHORT;
    
    
    int main()
    	
    {
    	USHORT Width = 5;
    	USHORT Length = 10;
    	Length = 10;
    	
    	USHORT Area = Width * Length;
    	
    	cout << "width:" << Width <<"\n";
    	cout << "length:" << Length << endl;
    	cout << "area:" << Area << endl;
    		return 0;
    }

  4. #4
    Join Date
    Aug 2013
    Beans
    76
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: compiler error in geany C++

    Quote Originally Posted by jinx3 View Post
    see but the last program had that typed exactly the same way as is here, i double checked it cause it was just added into the book at the point im on as is shown here:

    Code:
    #include <iostream>
    
    using namespace std;
    
    
    typedef unsigned short int USHORT;
    
    
    int main()
        
    {
        USHORT Width = 5;
        USHORT Length = 10;
        Length = 10;
        
        USHORT Area = Width * Length;
        
        cout << "width:" << Width <<"\n";
        cout << "length:" << Length << endl;
        cout << "area:" << Area << endl;
            return 0;
    }
    These all have the type along with a variable name, like the other poster mentioned. You need 'TYPE Variable = value;'

  5. #5
    Join Date
    Sep 2013
    Beans
    4

    Re: compiler error in geany C++

    well now i see exactly what i did and i feel like an idiot, anyway thanks for the help

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •