Thread: Im hopeless

  1. #1
    His posts are far and few Esparno's Avatar
    Join Date
    Mar 2002
    Posts
    100

    Im hopeless

    ok, im hopeless, someone help me with this. im getting wierd errors.

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<dos.h>
    #include<stdlib.h>
    #include<math.h>
    #include<windows.h>
    void gotoxy(int x, int y);
    int main
    {
    
    10:
    gotoxy (10, 10);
    cout>>"hello"
    goto 10;
       return 0;
    }
    
    void gotoxy(int x, int y)
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    
    }
    php tags turned into code tags by Salem

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    What sort of errors? The program not quitting?
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    cout << "Hello" not
    cout >> "Hello" as you have. Switch the operator >> for <<

  4. #4
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    a semicolon at the end of that line wouldn't hurt either
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  5. #5
    His posts are far and few Esparno's Avatar
    Join Date
    Mar 2002
    Posts
    100
    i knew it was going to loop forever, i planned it that way, this is just a test, and, thx, ill fix it right now

  6. #6
    His posts are far and few Esparno's Avatar
    Join Date
    Mar 2002
    Posts
    100
    Didnt work, heres the new revised code and the errors:

    9 c:\docume~1\john~1.esp\mydocu~1\ai.cpp syntax error before `{'
    13 c:\docume~1\john~1.esp\mydocu~1\ai.cpp syntax error before `<'
    PHP Code:
    #include<iostream.h>
    #include<conio.h>
    #include<dos.h>
    #include<stdlib.h>
    #include<math.h>
    #include<windows.h>
    void gotoxy(int xint y);
    int main
    {

    A:
    gotoxy (1010);
    cout<<"hello";
    goto 
    A;
       return 
    0;
    }

    void gotoxy(int xint y)
    {
       
    COORD coord;
       
    coord.x;
       
    coord.y;
       
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);


    Signature is optional, I didnt opt for one.

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You're missing the parentheses after main. The beginning should be:
    int main() // notice the parethseses
    {

    }

    Why are you using a goto? That's considered really bad programming. You could put whatever you want to loop in a forever loop(ex: for(;) or a while loop. Or you could put what you want to be repeated into a function and then call the function instead of using goto. If I ever used a goto in my programming class, my teacher would kill me. Don't don't don't use goto. Ever.

  8. #8
    His posts are far and few Esparno's Avatar
    Join Date
    Mar 2002
    Posts
    100
    I dont understand why goto is frowned upon, its easy to use and if you do it right its easy to identify, all you have to do is add
    "//(label)" at the end of each line, makes it easy to see where flow control is.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I dont understand why goto is frowned upon, its easy to use and if you do it right its easy to identify
    The problem is that 99% of goto users have no idea how to use it well, the other problem is that goto isn't as well recognized as more common looping constructs. I'm of your mind, if used properly and judiciously, goto can be very useful. But most of the time there are better solutions.

    -Prelude
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    C++ was designed not to need goto.

    Code:
    for( ; ; ){
       gotoxy (10, 10);
       cout<<"hello";
    }
    I came up with a cool phrase to put down here, but i forgot it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hopeless little c program
    By beone2 in forum C Programming
    Replies: 6
    Last Post: 06-17-2009, 06:43 PM
  2. hopeless
    By snowwhite212 in forum C++ Programming
    Replies: 2
    Last Post: 04-19-2009, 10:35 AM