Thread: New to C++ Programming: One error in compiler, Please Help.

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Question New to C++ Programming: One error in compiler, Please Help.

    Error E2451 C:\algorithim.cpp 18: Undefined Symbol 'cout' in function main.
    Error E2451 C:\algorithim.cpp 19: Undefined Symbol 'endl' in function main.
    Error E2451 C:\algorithim.cpp 22: Undefined Symbol 'cin' in function main.
    Any Suggestions?


    /*Question 5 Program*/

    int main()

    {
    int A;
    int B;
    int C;
    int D;
    int E;
    int F;
    int G;
    int N;
    int P;
    int S;
    int T;

    cout << "My first algorithim program.";
    cout << endl;
    cout << "Please enter pay rate";
    cout << endl;
    cin >> A;

    cout << endl;
    cout << "Please enter number of hours worked for this week.";
    cout << endl;
    cin >> B;

    cout << endl;
    cout << G = A * B;
    cout << "Income before taxes.";
    cout << A * B;

    cout << endl;
    cout << T = G * .14;
    cout << N = G - T;
    cout << "Income after taxes.";
    cout << G - T;

    cout << endl;
    cout << C = N * .10;
    cout << "Income spent on clothes and other accessories.";
    cout << N * .10;

    cout << endl;
    cout << D = N * .01;
    cout << "Income spent on school supplies";
    cout << N * .01;

    cout << endl;
    cout << F = C + D;
    cout << E = G - F;
    cout << S = E * .25;
    cout << "Income spent on savings bonds.";
    cout << E * .25;

    cout << endl;
    cout << P = S * .5;
    cout << "Money your parents matched to buy savings bonds";
    cout << S * .5;

    return 0;
    }
    Last edited by jljg23; 01-26-2010 at 03:44 PM.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Make sure you know the arithmetic operators of C++. Multiplication is not x, like you learned in school, it is an asterisk. The = sign always assigns to the left side as well.

    It is also really helpful to develop good habits early. Consider not using one-letter names and using words like gross, hours, and wage.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    thanks for the help, ill try to use that from now on

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    i am still getting the same error message though when i try to compile this updated program

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    int main();
    Something wrong there. Also, use [code][/code] tags when posting code samples.
    "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

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    thanks for that, now that problem is fixed but more error codes just came up.
    Error E2451 C:\algorithim.cpp 18: Undefined Symbol 'cout' in function main.
    Error E2451 C:\algorithim.cpp 19: Undefined Symbol 'endl' in function main.
    Error E2451 C:\algorithim.cpp 22: Undefined Symbol 'cin' in function main.
    any suggestions?

  7. #7
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Try including iostream.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  8. #8
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    yeah that didnt work either, it said it couldnt include iostream

  9. #9
    Allways learning cs_student's Avatar
    Join Date
    Aug 2008
    Location
    ~/
    Posts
    39
    Did you put
    Code:
    #include <iostream>
    at the top of your source file? (it might not be in your path)


    Also, remember that cout and cin are in namespace std.

  10. #10
    Registered User
    Join Date
    Dec 2009
    Posts
    30
    Code:
    #include <iostream>
    
    using namespace std;
    try adding that at top of code.

    also, are you giving us the full program? (just wanted to make sure you were including the right header files and all...)

  11. #11
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by dhardin View Post
    Code:
    #include <iostream>
    
    using namespace std;
    try adding that at top of code.

    also, are you giving us the full program? (just wanted to make sure you were including the right header files and all...)
    Oh please don't teach "using namespace std". That's a wonderful way to pollute the global namespace.

    Try "using std::cout", "using std::endl", and "using std::cin" if you have to use a using statement.

  12. #12
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    76
    Why not, does it change anything?

    Im new so its just a question

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM