Why doesn't "new line" work?

This is a discussion on Why doesn't "new line" work? within the C++ Programming forums, part of the General Programming Boards category; \n or <endl doesn't work......here's 2 test programs in which it doesn't work, but for others, it does....why? Code: #include ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    6

    Why doesn't "new line" work?

    \n or <endl doesn't work......here's 2 test programs in which it doesn't work, but for others, it does....why?

    Code:
    #include <iostream.h>
    int main()
     {
     int slot1
     int slot2
     int slot3
     int slot4
     int slot5
     int endr
     int sure
     cout<<"Please enter the top 5 things you would like to have if you were on an island alone"<<endl;
     cout<<"Type the first and most important thing"<<endl;
     cin>>slot1;
     cout<<"Type the second thing"<<endl;
     cin>>slot2;
     cout<<"Type the third thing"<<endl;
     cin>>slot3;
     cout<<"Type the fourth thing"<<endl;
     cin>>slot4;
     cout<<"Type the fifth thing and the one that you would least like to have"<<endl;
     cin>>slot5;
     cout<<"You liked the following in order"<<endl;
     cout<<"1. "slot1 <<endl;
     cout<<"2. "slot2 <<endl;
     cout<<"3. "slot3 <<endl;
     cout<<"4. "slot4 <<endl;
     cout<<"5. "slot5 <<endl;
     cout<<"Am I right?";
     cin>>endr;
     if(endr==yes)
      {
      cout<<"I knew it!";
      }
     else if(endr==y)
      {
      cout<<"I knew it!";
      }
     else if(endr==ya)
      {
      cout<<"I knew it!";
      }
     else if(endr==yup)
      {
      cout<<"I knew it!";
      }
     else
      {
      cout<<"Are you sure?";
      cin>>sure;
      }
     if(sure==yes)
      {
      cout<<"Sure....whatever you say...";
      }
     else
      {
      cout<<"I knew it!";
      }
     return 0;
     }
    and shorter terms......

    Code:
    #include <iostream.h>
    int main()
    {
     cout<<"line 1" <<endl;
     cout<<"line 2" <<endl;
     return 0;
    }
    Last edited by Moron Slayer; 12-20-2003 at 12:47 PM.

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    This code should work,
    Code:
    #include <iostream>
    using namespaces std;
    
    int main()
    {
      cout << "hello 1" << endl;
      cout << "hello 2" << endl;
    }

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You're missing at least seven semi-colons. That will cause a compile-time parse error -- seven, actually.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  4. #4
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269

    Exclamation ...

    Simple, declare endl:

    Code:
    using namespace std;
    or

    Code:
    using std::cin;
    using std::cout;     //Better one
    using std::endl;
    Either one will work.

    -SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  5. #5
    Registered User
    Join Date
    Dec 2003
    Posts
    6
    none of them work

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    What OS/compiler are you using?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User
    Join Date
    Dec 2003
    Posts
    6
    WinXP Pro, Dev-C++

  8. #8
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    are you using dev c++ 4.9.8.0 or higher? If so, i've had the same problem and known many who have had it under windows xp

  9. #9
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    and

    cout<<"1. "slot1 <<endl;
    cout<<"2. "slot2 <<endl;
    cout<<"3. "slot3 <<endl;
    cout<<"4. "slot4 <<endl;
    cout<<"5. "slot5 <<endl;


    you're missing << before the variable names. unless you put the quotation marks in the wrong spot.

  10. #10
    Registered User
    Join Date
    Dec 2003
    Posts
    6
    thanks...it helped...

    1) I changed my compiler to Dev C++ 4 from 4.something
    2) I fixed the

    Code:
    cout<<"1. "slot1 <<endl;
    cout<<"2. "slot2 <<endl;
    cout<<"3. "slot3 <<endl;
    cout<<"4. "slot4 <<endl;
    cout<<"5. "slot5 <<endl;
    problem

  11. #11
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Originally posted by laasunde
    Code:
    #include <iostream>
    using namespaces std;
    
    int main()
    {
      cout << "hello 1" << endl;
      cout << "hello 2" << endl;
    }
    return 0;

  12. #12
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Originally posted by BMJ
    return 0;
    The return 0 is optional; an implicit return 0 exists for main() if no return statement is provided. (Some older compilers don't accept this).

  13. #13
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    It's optional, yes, but the standard is to use it.
    Do not make direct eye contact with me.

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Originally posted by Lurker
    It's optional, yes, but the standard is to use it.
    Quick, someone find Prelude ...

    Rate My Application: File Stream/Bubble Sort

  15. #15
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Originally posted by Lurker
    It's optional, yes, but the standard is to use it.
    Whose standard?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  4. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM
  5. How do i make a "new line" with in an edit box?
    By Clyde in forum Windows Programming
    Replies: 3
    Last Post: 05-18-2002, 01:35 PM

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