error

This is a discussion on error within the C++ Programming forums, part of the General Programming Boards category; Hello. When i write this code it shows error " end1 undeclared(first use here)". What does it mean? It is ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    13

    error

    Hello. When i write this code it shows error " end1 undeclared(first use here)". What does it mean? It is from the book "C++ How To Program Fifth Edition" Im using Dev C++ compiler.
    Code:
       
       
       #include <iostream> 
     
      
       int main()
       {
          
          int number1; 
         int number2; 
         int sum; 
    
         std::cout << "Enter first integer: "; 
         std::cin >> number1; 
    
         std::cout << "Enter second integer: "; 
         std::cin >> number2; 
    
        sum = number1 + number2; 
    
         std::cout << "Sum is " << sum << std::end1; 
    
         return 0; 
    
      }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    end1 should be endl ("one" versus lowercase "L").

    Incidentally, you might want to indent your code a little more consistently to make it easier for you to read later on. For example:
    Code:
    #include <iostream>
    
    
    int main()
    {
    
        int number1;
        int number2;
        int sum;
    
        std::cout << "Enter first integer: ";
        std::cin >> number1;
    
        std::cout << "Enter second integer: ";
        std::cin >> number2;
    
        sum = number1 + number2;
    
        std::cout << "Sum is " << sum << std::end1;
    
        return 0;
    
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    13
    Thank you. It works. But still it doesnt show me the sum when i press enter after i write the second number.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    You can run the program from the command line instead. If you really wish to run it from Dev-C++, you would need to keep the window open by pausing. One way is to wait for input, e.g.,
    Code:
    std::cout << "Sum is " << sum << std::end1;
    
    std::cin.ignore(); // Ignore the newline character in the input buffer.
    std::cin.get();    // Wait for the user to press enter.
    
    return 0;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    13
    Still nothing. I dont know why. I can type first and the second number but after that when i press enter the window just dissappears.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    Still nothing. I dont know why. I can type first and the second number but after that when i press enter the window just dissappears.
    What is your current code?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    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.

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    13
    This is my code.

    Code:
    #include<iostream>
    int main()
    {
    
    int number1;
    int number2;
    int sum;
    
    std::cout<<"Enter first integer:";
    std::cin>>number1;
    
    std::cout<<"Enter second integer:";
    std::cin>>number2;
    
    sum= number1+number2;
    
    std::cout<<"Sum is"<<sum<<std::endl;
    
    std::cin.get();
    
    
    
    
    return 0;
    
    }
    Maybe the code is wrong i dont know i just rewrote this from the book.
    Last edited by muray; 02-01-2008 at 11:25 AM.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    The cin.get() is not enough. Notice the cin.ignore() in my example.

    Elysia linked to the relevant cprogramming.com FAQ with a more comprehensive explanation and examples. You could also read our cpwiki entry on How to keep a Windows console from closing though it is not quite up to scratch just yet.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    May 2007
    Posts
    13
    I have tried everything but still nothing. The console just keeps closing. Thank you for help anyway.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    hmm... that's strange. Try this:
    Code:
    #include <iostream>
    #include <ios>
    #include <limits>
    
    int main()
    {
        int number1;
        int number2;
        int sum;
    
        std::cout << "Enter first integer: ";
        std::cin >> number1;
    
        std::cout << "Enter second integer: ";
        std::cin >> number2;
    
        sum = number1 + number2;
    
        std::cout << "Sum is " << sum << std::endl;
    
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        std::cin.get();
    
        return 0;
    }
    Generally, I think it is usually better to just run the program from the command line.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    May 2007
    Posts
    13
    It says no such file directory for ios and limits.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,781
    What exact version of Dev-C++ are you using? It should be version 4.9.9.2, otherwise you need to upgrade.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Registered User
    Join Date
    May 2007
    Posts
    13
    When i install and run new version it says "There doesnt seem to be GNU Make file in PATH or in Dev-C++ Bin path.

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    I think you need to uninstall the old one before updating.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21