Thread: problem with Dev-C++ & main()

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    problem with Dev-C++ & main()

    am watching *Compiling & Executing Programs Demo* at
    http://www.computer-training-software.com/c.htm
    and i stumbled upon this
    Code:
    1 C:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31,               from C:\Dev-Cpp\test\Untitled1.cpp In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31,               from C:\Dev-Cpp\test\Untitled1.cpp 
    1 C:\Dev-Cpp\test\Untitled1.cpp                  from C:\Dev-Cpp\test\Untitled1.cpp 
    32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. 
    4 C:\Dev-Cpp\test\Untitled1.cpp `main' must return `int' 
     C:\Dev-Cpp\test\Untitled1.cpp In function `int main(...)': 
    16 C:\Dev-Cpp\test\Untitled1.cpp `end1' undeclared (first use this function) 
      (Each undeclared identifier is reported only once for each function it appears in.)
    this is my code
    Code:
    #include <iostream.h>
    
    void main()
    {
         float num1;
         float num2;
         float total;
         
         cout << "Enter a value for this first virable: ";
         cin >> num1;
         cout << "Enter a value for this first virable:  ";
         cin >> num2;
         
         total = num1 + num2;
         
         cout << "The sum of the numbers = " << total << end1;
        
    }

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    The manipulator is endl (as in line) not end1 (as in one). Also main should be declared as an int, not void. Other than that, you're just getting deprecated warnings on your library. At this point you might want to ignore that for now until your get a grasp on the basics.
    Sent from my iPadŽ

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Do exactly as the compiler tells you. main returns an int. You have it written as returning void which has no advantage whatsoever.

    Also, iostream.h is old.
    #include <iostream>

    Everything else looks fine to me, except after you include that you should also type
    uning std::cout;
    using std::endl;

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1
    It's not virable, it's variable

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    7
    its not my fault that the man in the turtuial is using a old iostream

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    .... He's not going to teach you to use gets() is he?

    I was watching this. He keeps referring to C++ as C (and even the compiler as C), which is going to confuse people. You and all of his students need to make the distinction quickly that C is not C++, and a compiler is not C either. I want to recommend that you stop watching these immediately and that they are taken off the internet, but alas I cannot do anything that drastic.

    This poor unfortunate soul.

  7. #7
    Registered User
    Join Date
    Jul 2006
    Posts
    7
    thanks guys
    finly i got the sample calc working <3

  8. #8
    Registered User
    Join Date
    Jul 2006
    Posts
    7
    but it wont stay there it closes right after i inputs numbers
    hmm
    Last edited by wiak; 07-12-2006 at 11:18 PM.

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The instructor said that endl will pause the console. I actually haven't had very much experience with the old iostream.h, but I think that he is very wrong about that. You should also not rely on whether or not he is right. endl simply puts a newline onto the screen and then "flushes" the output buffer.

    There are a couple of things you can do to see the output of your program.
    - My personal favorite, run the program in a console you opened yourself. That way, the console will not close until you type exit. Just drag and drop your executables into the console window.
    - You could pause the program with something like
    cin.ignore();
    cin.get();
    Where ignore will grab a newline that might be in the input buffer, and get will wait for more input before closing the program. Just press enter to close. Beware though, sometimes more than one character will be in the input stream and modifications will need to be made to ignore(). This is one of the reasons why I like running my programs from my own console window.
    Last edited by whiteflags; 07-12-2006 at 11:37 PM.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Or switch to Visual C++ or Code::Blocks, both of which are smart enough to automatically run console apps in a small wrapper application that keeps the console open.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Registered User
    Join Date
    Jul 2006
    Posts
    7
    Quote Originally Posted by CornedBee
    Or switch to Visual C++ or Code::Blocks, both of which are smart enough to automatically run console apps in a small wrapper application that keeps the console open.
    nah i wont use Micro$oft Visual C++, also it uses like 2GB space and Dev-C++ used 65MB
    gonna check out code:blocks now

  12. #12
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by wiak
    nah i wont use Micro$oft Visual C++, also it uses like 2GB space and Dev-C++ used 65MB
    gonna check out code:blocks now
    That's the entire .NET framework taking up that space. As well as all their other utilities for C#, J#, etc... If you aren't limited on disk space, I'd recommend installing all the compilers you can get your hands on, so long as they're standard.
    Sent from my iPadŽ

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with using for loops with Dev C++
    By indigo0086 in forum C++ Programming
    Replies: 10
    Last Post: 08-10-2005, 11:04 PM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  3. Dev Resource problem
    By algi in forum Windows Programming
    Replies: 3
    Last Post: 04-19-2005, 03:53 PM
  4. Resources with Dev C++ Problem (many simple problems)
    By Zeusbwr in forum Windows Programming
    Replies: 4
    Last Post: 04-06-2005, 11:08 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM