Im a noob with an easy question

This is a discussion on Im a noob with an easy question within the C++ Programming forums, part of the General Programming Boards category; I have a program which is small and easy the code is Code: #include<iostream> using namespace std; int main (void) ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    3

    Im a noob with an easy question

    I have a program which is small and easy the code is

    Code:
    #include<iostream>
    using namespace std;
    
    int main (void)
    {	
    
    	double dnumber1=0.0;
    	double dnumber2=0.0;
    	double dnumber3=0.0;
    	double daverage=0.0;
    	
    	cout << "Please Enter 3 Numbers " <<endl;
    	cin >> dnumber1;
    	cin >> dnumber2;
    	cin >> dnumber3;
    	
    	daverage = (dnumber1 + dnumber2 + dnumber3) / 3;
    	
    	cout << "The Average Of The Numbers Is: " <<daverage <<endl; <<endl; //Problem is in this line
    	
    	system("pause");
    	return 0;
    
    }
    that is a short easy program but I get the error saying
    "19 expected primary-expression before '<<' token "

    I am using Devc++ the newest beta version

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    Code tags on the first post! Very nice.

    <<endl; <<endl;

    Remove the red part.

    gg

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    3
    Thanks for recognizing my code tags Its whats used everywhere on any forum

    why does the other endl; have to be taken off doesn't that just make an extra line

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by mark9510
    why does the other endl; have to be taken off doesn't that just make an extra line
    The problem is that there is a terminating semi-colon sandwiched right there. If you want that second endl, then you should write:
    Code:
    cout << "The Average Of The Numbers Is: " << daverage << endl << endl;
    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
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,596
    A new line is just endl, not endl;.
    And every line (except for control statements) must end with a ;.
    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.

  6. #6
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    endl is just a variable/constant at all.

    so putting a statement like
    Code:
    endl;
    or
    Code:
    dnumber1;
    Means nothing but error.
    Just GET it OFF out my mind!!

  7. #7
    Registered User
    Join Date
    Dec 2008
    Posts
    18
    Like codeplug said, it's this part:

    Code:
    <<endl; <<endl;
    .

    Basically, you only use the ';' after each line, not between functions on the same line . Take off the first ';'.

    Code:
    <<endl << endl;
    will work .

    Good luck!
    Thanks.
    Last edited by sharkbate24; 01-01-2009 at 12:00 PM.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by audinue
    endl is just a variable/constant at all.
    Actually, std::endl is a function (template).
    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

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    3
    Thanks alot for your help I now understand

  10. #10
    Registered User
    Join Date
    Dec 2008
    Posts
    18
    Quote Originally Posted by mark9510 View Post
    Thanks alot for your help I now understand
    Great! No Problem .

    It does take quite a while to get used to, but once you're used to it, you'll be doing it automatically (like me ).
    Also, I would recommend commenting your code. You don't really need to in a simple script like this one, but it's just a starting point so you can get used to it .

    Happy new year!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 10:43 PM
  2. Noob here...a simple question.
    By The_Mayor in forum C Programming
    Replies: 4
    Last Post: 06-08-2005, 12:48 AM
  3. Quick Easy Question
    By St0rmTroop3er in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-24-2004, 12:08 AM
  4. Easy Question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-12-2002, 12:19 PM

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