Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

British Flag

Status
Not open for further replies.

rwese3

Programmer
Feb 17, 2001
3
US
I am having a problem with my class and I need some help. We were assigned to make a british flag graphic without the border. I cannot use an array to create a field for the graphics because we haven't learned that yet. I must use things like gotoxy (x,y) , for, if, end, else, and goto statements, you know, elementary stuff. Supposedly this gotoxy (x,y) statement will help me solve the problem of creating one graphic line like the \ diagonal and being able to go back to the first line to start the second graphic line of the flag. What the teacher said was basically the logic will go as follows: declare the variables with the for statement, then goto the first x value (0) and when y=x, print an ASCII character. Then use the \n to go to the next line and repeat. I figure to use a 20 x 20 field to keep it simple and square. I have the following code so far and am sure some of the lines are either out of order, improperly syntaxed or not necessary.
#include<iostream.h>
#include<conio.h>
int x;
int y;
void main()
{
for(int x=0, y=0; x<20, y<20; x++, y++)
if (x==20) goto done;
gotoxy(x,y);
cout << &quot;\x03&quot; &quot;\n&quot;;
done:
cin >> &quot;&quot;;
return;
}
this is my best stab at it so far and my compiler is called Quincy 97 and is bound to be coming up with more errors than if it were running on the Borland's at School, but it is coming up with the following errors:
assignment5.cpp:12: warning: implicit declaration of function `int gotoxy(...)'
assignment5.cpp:12: warning: name lookup of `x' changed for new ANSI `for' scoping
assignment5.cpp:10: warning: using obsolete binding at `x'
assignment5.cpp:12: warning: name lookup of `y' changed for new ANSI `for' scoping
assignment5.cpp:10: warning: using obsolete binding at `y'
assignment5.cpp:16: warning: `return' with no value, in function returning non-void
Any help would be appreciated greatly.
Richard W.
 
rwese3,

[tab]I don't mean to be nitpicking but you should take a careful look at zBuilder's posting. It will show you a better form in programming. This is NOT a criticism of your coding. I realize that you are just beggining, but the following points should help further your grade/career/etc..

1)int main(); The C++ standard now &quot;requests&quot; this. At some point they may require this so any programs that have void main() won't compile anymore.

2)int x; int y; You have defined these twice. Once on a global scope and another in the scope of the loop. This really isn't a &quot;bad&quot; thing but it makes your code look bette and more manageable. If you really need global scope, use it but it isn't necessary in your current code.

3)goto done; Unless you are required to use this by your instructor, avoid its use! There have been some arguments for its use so it is included in the standard but if you send in a sample of your coding with a goto statement to a prospective employer, they may look at the &quot;goto&quot; and think &quot;spagetti code.&quot;

4)return 0; Since &quot;main&quot; requires an integer (see #1 above) return must return an integer.

Good luck. James P. Cottingham
 
Thanks to the start from ZBUILDER and 2ffat I can complete this now...and don't worry James, any helpful tips from someone in the real programming world are definitely appreciated! I have only been at the programming for 6 weeks now, but have been helpdesking for 3 or 4 years. As far as programming goes, I know I have alot to learn. my code is looking like this now and I have used this to produce both diagonal lines now. It should not be hard to proceed now, thanks to the jump-start.

#include<iostream.h>
#include<conio.h>
int main()
{
int x;
for(x=0; x<20; x++)
{
gotoxy(x,x);
cout << &quot;\x03&quot;;
}
int y;
for(y=20 , x=0; y>0 , x<20 ; y-- , x++)
{
gotoxy(x,y);
cout << &quot;\x03&quot;;
}
getch();
return 0;
}

Thanks Very Much!
Richard Weseman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top