Thread: sams C++ 21 days code error

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    6

    sams C++ 21 days code error

    Hi, im new to C++ and im using sams teach youself C++ in 21 days fifth edition to help me learn.

    Iv just got to the end of day one and an one of the excersises it to guess what the code does before we run it, but when i did compile an run it i had some problems.. This is the code..

    Code:
    #include <iostream>
    int main()
    {
        int x = 5;
        int y = 7;
        std::cout << end1;
        std::cout << x + y << " " << x * y;
        std::cout << end;
        char response;
        std::cin >>response;
        return 0;
    }
    Im using Bloodshed dev and these are the errors i got..

    line 4 'end1' undeclared (first use this function)

    and

    line 8 'end' undeclared (first use this function).

    It may be something simple but im completely new to this so i wouldnt know..

    Any help would be greatly appreciated.

    Thanks

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    42
    The endline function is not "end1". It's endl and it belongs to namespace std, just like cout and cin, so you have to change it to std::endl.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    Thanks for the fast reply .

    i changed it to this now

    Code:
    #include <iostream>
    int main()
    {
        int x = 5;
        int y = 7;
        std::endl;
        std::cout << x + y << " " << x * y;
        std::cout << end;
        char response;
        std::cin >>response;
        return 0;
    }
    but now i have an error saying

    line 6 statement cannot resolve address of overloaded function

    and

    line 8 'end' undeclared (first use this function).

    Sorry if im just being dumb..

    Thanks

  4. #4
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by marbles View Post
    Thanks for the fast reply .

    i changed it to this now

    Code:
    #include <iostream>
    int main()
    {
        int x = 5;
        int y = 7;
        std::endl;
        std::cout << x + y << " " << x * y;
        std::cout << end;
        char response;
        std::cin >>response;
        return 0;
    }
    but now i have an error saying

    line 6 statement cannot resolve address of overloaded function

    and

    line 8 'end' undeclared (first use this function).

    Sorry if im just being dumb..

    Thanks
    Where are you delcaring 'end'? You need to declare it before you can use it.

    You need to use
    Code:
    std::cout << std::endl;
    or just
    Code:
    std::cout << "\n";
    if you want a new line
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    ok, again thanks for the fast reply, the error on line 6 has gone now

    what does
    Code:
    std::cout << std::endl;
    actually do?

    I still have the same one on line 8 though lol =/


    thanks a lot for the help

  6. #6
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by marbles View Post
    ok, again thanks for the fast reply, the error on line 6 has gone now

    what does
    Code:
    std::cout << std::endl;
    actually do?

    I still have the same one on line 8 though lol =/


    thanks a lot for the help
    It simply puts a new-line character into the stream, and it also flushes the buffer.

    You have to declare the variable you want to use. For example,
    Code:
    int myvariable;
    Or in your case,
    Code:
    int end;
    However, I don't know what you're trying to do by displaying an empty variable
    Last edited by Sentral; 03-12-2009 at 06:54 PM.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    ah ok.. i sorta understand..

    thanks very much for your help.

    i now have
    Code:
    #include <iostream>
    int main()
    {
        int x = 5;
        int y = 7;
        std::cout << std::endl;
        int end;
        std::cout << x + y << " " << x * y;
        std::cout << "\n";
        std::cout << end;
        char response;
        std::cin >>response;
        return 0;
    }
    and it runs!

    my output is

    12 35
    2293640

    was this the expected output?

    where the hell did 2293640 come from lol?

    thanks

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    when i took out the
    Code:
    std::cout << end;
    it take that number away so i know its that thats making that number appear, just dont know why...


    thanks

  9. #9
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by marbles View Post
    when i took out the
    Code:
    std::cout << end;
    it take that number away so i know its that thats making that number appear, just dont know why...


    thanks
    It's because you didn't initialize 'end' to anything. The computer simply assigns 'end' a random number. You must do,
    Code:
    int end=25;
    or whatever you want
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  10. #10
    Registered User
    Join Date
    Nov 2008
    Posts
    6
    ohhh i seee.

    Ok then, thanks so much for all your help =)!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM