C++ Help
Results 1 to 10 of 10

Thread: C++ Help

  1. #1

    C++ Help

    Whats wrong with this code?

    #include <stdlib.h>
    #include <conio.h>
    #include <iostream>
    using namespace std;
    */
    int main()
    do
    {
    cout << "Still in the do...while loop" << endl;
    } while (!kbhit());
    return EXIT SUCCESS
    }

    The error message is:
    Line 5: parse error before '/'

    Any Suggestions?

  2. #2
    oblio
    Guest
    #include <stdlib.h>
    #include <conio.h>
    #include <iostream>
    using namespace std;

    int main(){
    do
    {
    cout << "Still in the do...while loop" << endl;
    } while (!kbhit());
    return 0
    }

  3. #3

    Post

    Shmoo, I looked over the code for the hello world program you showed us in the irc. Here is what my version looks like.

    #include <iostream.h>
    int main()
    {
    cout << "Hello World!";
    return(0);
    }
    Jealousy consumes the weak.
    http://www.badconnections.net

  4. #4
    Senior Member
    Join Date
    Nov 2001
    Posts
    257
    You ended a comment without starting one, */ should be placed after a comment with /* before it.
    -Shkuey
    Living life one line of error free code at a time.

  5. #5
    Senior Member
    Join Date
    Sep 2001
    Posts
    138
    You can technically use all the */'s you want in your code without an adverse effects... Just thought I would comment on that...
    http://www25.brinkster.com/cheeseball

    -- Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment--

  6. #6
    #include <stdlib.h>
    #include <conio.h>
    #include <iostream>
    using namespace std;
    */
    int main()
    do
    {
    cout << "Still in the do...while loop" << endl;
    } while (!kbhit());
    return EXIT SUCCESS
    }


    Well Shmoo I get 7 errors with this code, so obivious stuff your doing wrong
    1) <iostream> should be <iostream.h>
    2) */ needs a closing comment */
    3) your do statement is all messed up
    4) wtf is (!kbhit()); I've never seen that in my life
    5)if your going to use <conio.h> make sure you use getch(); to or else you defeat it's purpose
    6)Learn how to do a while loop and execute conditions

    here is an example, this program doesn't need that **** use void main () and get rid of it
    If you need more help let me know


    #include <iostream.h>

    void main()
    {
    int x = 1;

    while( x = 1)// put your loop condition in here
    {
    cout << "Still in the do...while loop";

    }

    }

    Yes this is a never ending loop..

  7. #7
    Member
    Join Date
    Dec 2001
    Posts
    94
    remove all .h in header files and remove the */

    about the */ why have you used it ??

    freeon:

    kbhit() is a function that allows a process to happen while the user presses a key
    it's in conio.h so he's right

  8. #8
    I never heard that **** before, but it's good to know

  9. #9
    Senior Member
    Join Date
    Jul 2001
    Posts
    138
    <iostream> should be <iostream.h> isn't exactly correct. <iostream.h> is deprecated in favor of using namespaces. instead of doing:

    using namespace std...
    why don't you just do
    using std::cout;
    using std::cin;
    using std::endl;

    In other words, only call the objects from the namespace you absolutely need. The whole
    reason <iostream.h> is deprecated is so you can use the namespace in this manner. Any
    decent optimizing compiler should strip out unneeded objects anyway, but this enforces that
    for any compiler that doesn't. Just thought I would mention this.

    Happy Hacking
    -----------------------------------------------------
    Warfare is the Way of deception.
    -Sun Tzu \"The Art of War\"

  10. #10
    Junior Member
    Join Date
    Mar 2002
    Posts
    10
    I have noticed that there is a curly bracket missing between the int main() and do...
    you actually have it as

    #include ..... blah blah

    int main()
    do
    {
    ....
    }
    }

    it should be

    ...
    int main()
    {
    do
    {
    ...
    }
    }

    the indents are not necesary, but it makes it clearer to me for reading. I don't know about the kbhit() function... I have never seen it b4 either... but that does not mean it does not exist

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •