Thread: error

  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
    28,413
    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;
    
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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 12:25 PM.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    What exact version of Dev-C++ are you using? It should be version 4.9.9.2, otherwise you need to upgrade.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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.

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, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM