Newbi Hel/newbi question

This is a discussion on Newbi Hel/newbi question within the C++ Programming forums, part of the General Programming Boards category; Why won't this code work? I'm trying to make a function that just displays text. Code: #include <stdio.h> #inclide <iostream.h> ...

  1. #1
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77

    Newbi Hel/newbi question

    Why won't this code work?

    I'm trying to make a function that just displays text.

    Code:
    #include <stdio.h>
    #inclide <iostream.h>
    
    void displayinfo(void)
    {
          cout << "Copyright 2003";
    
    }
    
    main()
    {
    
      system ("pause")
     return 0;
    }
    it won't display the text, can you tell me why it won't tanxs


    ~Trooper

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    The reason why it wont run is because you havent called the function in the main.

    you dont need the <stdio.h>

    and in the main function add this line before system("PAUSE");
    displayinfo();

    also include <stdlib.h>

    this should fix it

    Code:
    #include <stlib.h>
    #inclide <iostream.h>
    
    void displayinfo(void)
    {
          cout << "Copyright 2003";
    
    }
    
    main()
    {
      displayinfo()
      system ("pause")
     return 0;
    }

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    You never called the displayinfo() function...

    try
    Code:
    #include <stdio.h>
    #inclide <iostream.h>
    
    void displayinfo(void)
    {
          cout << "Copyright 2003";
    
    }
    
    int main()
    {
       displayinfo();
      system ("pause");
     return 0;
    }
    Oh, and you're using depreciated headers.
    Away.

  4. #4
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    And you should use prototypes:
    Code:
    #include <iostream>
    using namespace std;
    
    void displayinfo();
    
    int main()
    {
       displayinfo();
    
      system ("pause");
     return 0;
    }
    
    void displayinfo()
    {
          cout << "Copyright 2003";
    }
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  5. #5
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    okay thanks

    Oh, and you're using depreciated headers.

    Umm what is that ? lol I'm new lol.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    The deprecated headers are headers like iostream.h, stdlib.h. they should be iostream and cstdlib. there are more, and more info should be able to found in the faq

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    here's an excerpt from the backwards warning that a Dev C++ compiler will give you:
    Code:
    #ifndef _CPP_BACKWARD_IOSTREAM_H
    #define _CPP_BACKWARD_IOSTREAM_H 1
    
    #include "backward_warning.h"
    #include <iostream>
    
    using std::iostream;
    using std::ostream;
    using std::istream;
    using std::ios;
    using std::streambuf;
    
    using std::cout;
    using std::cin;
    using std::cerr;
    using std::clog;
    #ifdef _GLIBCPP_USE_WCHAR_T
    using std::wcout;
    using std::wcin;
    using std::wcerr;
    using std::wclog;
    #endif
    
    using std::ws;
    using std::endl;
    using std::ends;
    using std::flush;
    
    #endif
    don't know if you'll be able to figure it out from that, but oh well...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Originally posted by HybridM
    And you should use prototypes:
    Code:
    #include <iostream>
    using namespace std;
    
    void displayinfo();
    
    int main()
    {
       displayinfo();
    
      system ("pause");
     return 0;
    }
    
    void displayinfo()
    {
          cout << "Copyright 2003";
    }
    Is it really necessary to use prototypes in such a basic program? I mean, is there actually any difference in performance/efficiency? Just asking.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by bennyandthejets
    Is it really necessary to use prototypes in such a basic program? I mean, is there actually any difference in performance/efficiency? Just asking.
    I don't know if it makes too much of a difference for such a basic program, but imo, it does give you practice for habits in prototyping larger programs

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    yes there is a effiency difference. in memory.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  11. #11
    using namespace Trooper; St0rmTroop3er's Avatar
    Join Date
    Sep 2003
    Posts
    77
    [code]

    int main()
    {
    Displayinfo()
    system("Pause")
    }

    I have a problem again, it says that there is a pase erre befr '}' and when I delet Displayinfo it works but won't show the info. could you help me pls?

    ~Trooper

  12. #12
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Originally posted by St0rmTroop3er
    Code:
     pase erre befr '}'
    Code:
    int main()
    {
      DisplayInfo();
      system("pause");
      return 0;
    }

  13. #13
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    AHh dont forget your semicolons man there most important.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  14. #14
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    Your second include statement is inclide you may want to change that.

  15. #15
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Good eye, yeah that definitely won't compile ...

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

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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