Thread: Errors, please help [Newb]

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    Errors, please help [Newb]

    Hello I just started programming and managed to make some programs, but what I don't get is when I get these errors:

    Compiler: Default compiler
    Executing gcc.exe...
    gcc.exe "D:\Documents and Settings\Riikard\Desktop\Untitled1.c" -o "D:\Documents and Settings\Riikard\Desktop\Untitled1.exe" -g3 -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:1:20: iostream: No such file or directory
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:3: error: syntax error before "namespace"
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:3: warning: data definition has no type or storage class

    D:\Documents and Settings\Riikard\Desktop\Untitled1.c: In function `main':
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:12: error: `cout' undeclared (first use in this function)
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:12: error: (Each undeclared identifier is reported only once
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:12: error: for each function it appears in.)
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:12: error: `endl' undeclared (first use in this function)
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:13: error: `cin' undeclared (first use in this function)
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:17: error: `davarge' undeclared (first use in this function)
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:21: error: `system' undeclared (first use in this function)
    D:\Documents and Settings\Riikard\Desktop\Untitled1.c:21: error: syntax error before ';' token

    Execution terminated

    I include iostream and all these code in the program but I still get these errors, it has happen before aswell and I got no clue why, sometimes it works sometimes it dosent, anyone knows why?

    I used to get this problem when i used code blocks aswell, thats why I uninstalled codeblocks and downloaded Dev-C++ version 4.9.9.2 but now I still get the same errors.

    Here's the code btw:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
        double dnumber1 = 0.0;
        double dnumber2 = 0.0;
        double dnumber3 = 0.0;
        double davarage = 0.0;
    
        cout << "Please enter 3 numbers: " << endl;
        cin >> dnumber1;
        cin >> dnumber2;
        cin >> dnumber3;
    
        davarge = (dnumber1 + dnumber2 + dnumber3) / 3;
    
        cout << "The avarge of the numbers are: " << davarage << endl << endl;
    
        system |"pause"| ;
        return 0;
    
    }
    Thank you.

  2. #2
    Registered User
    Join Date
    Oct 2009
    Posts
    38
    are you sure you're writing it in a .cpp file? because from the errors it looks like you're in a .c file which is for programming c not c++. im not completely sure thats it (im a "newb" too) but thats what it looks like to me.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    #1. I don't use that compiler, but I'm thinking you want to name your file with a .CPP extension (as already mentioned) and perhaps try using g++ instead of gcc at the command line, I believe the former is the C++ compiler and the later is the C compiler (though I could be wrong).



    #2.
    Code:
        double davarage = 0.0;
    
        cout << "Please enter 3 numbers: " << endl;
        cin >> dnumber1;
        cin >> dnumber2;
        cin >> dnumber3;
    
        davarge = (dnumber1 + dnumber2 + dnumber3) / 3;
    
        cout << "The avarge of the numbers are: " << davarage << endl << endl;
    Typo? That takes care of the "error: `davarge' undeclared (first use in this function)" problem.



    #3
    Code:
    system |"pause"| ;
    That's not in any way, shape, or form the proper method for calling system... that plus you'd need to include the <cstdlib> or <stdlib.h> header depending on what language you're actually using here. It works just like any other function call:
    Code:
    system("pause");



    [edit]Yay! Post #3000!!![/edit]
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Jun 2010
    Posts
    4
    or you could get rid of the iostream and use fprint, so the c compiler can compile it as c code :P

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    4
    o.o i'm even forgetting c's function names

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This is C++, not C, so that suggestion is silly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM