-
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
-
What sort of errors? The program not quitting? ;)
-
cout << "Hello" not
cout >> "Hello" as you have. Switch the operator >> for <<
-
a semicolon at the end of that line wouldn't hurt either
-
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
-
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 x, int y);
int main
{
A:
gotoxy (10, 10);
cout<<"hello";
goto A;
return 0;
}
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
-
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.
-
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.
-
>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
-
C++ was designed not to need goto.
Code:
for( ; ; ){
gotoxy (10, 10);
cout<<"hello";
}