|
From: Ioannis V. <no...@ho...> - 2002-08-08 08:15:49
|
I assume you coded in C.=20
=20
=20
=20
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Carlos
Garc=EDa del Monte
Sent: Wednesday, August 07, 2002 9:44 PM
To: dev-cpp-users-list
Subject: [Dev-C++] compiler psychiatrics
Here is an old experiment for programming, when I still did not know
C++, (only a piece of the program, so I don't get you buried under a ton
of code). You run fine?=20
There are two lines, in red, that invert their order, the scanf is done
before its printf.=20
printf("and then choose the weight\n");//THESE TWO LINES CHANGE THE
ORDERING!!!!!=20
scanf("%d\n", &weight);=20
You see (adding two lines before)=20
___________________________________=20
| Title _0X |=20
|-----------------------------------------------|=20
| [...] |
| Choose the height. |=20
| 180 |=20
| _ |=20
|___________________________________|=20
The program asks for the height, you enter the height you want, 180, and
then you wait the next prompt for the weight, but you find there is the
cursor one line below, waiting your input...=20
___________________________________=20
| Title _0X |=20
|-----------------------------------------------|=20
| Choose the height. |=20
| 180 |=20
| 80 |=20
| And then choose the weight |=20
|___________________________________|=20
And you enter any number, then the prompt appears, and from now on all
inputs are before its prompt. When the moment arrives when the program
prints your character's statistics you see what went where. It continues
doing so till the end.=20
Copying the scanf after the printf and having two scanf only makes the
error repeat in the next pair printf/scanf=20
The best is that it happens when I compile it with borland 5.5.=20
/*a text-based fighting game*/=20
#include <stdio.h>=20
#include <stdlib.h>=20
#include <time.h>=20
int main()=20
{=20
int genre, level, answ, result, end, weight, tall, radius, prop, pula;=20
int vic, mvic, round, mov, mmov, posa, posb, posc, posd, pose, monster,
hit;=20
int agil, magil;=20
int a, u;=20
int difab, difup, difpta, difptb;=20
int strenght;=20
int abwer, upwer, piwer, mawer, cabwer, arwer;=20
int mabwer, mupwer, mpuiwer, mmawer, mcabwer, marwer;=20
int atpts, dfpts, agpts, witpts, velpts, dampts, sufpts, respts;=20
int matpts, mdfpts, magpts, mwitpts, mvelpts, mdampts, msufpts, mrespts;
int oat, odf, oag, owit, ovel, odam, ores;=20
char name[20];=20
char wear[16];=20
char clothab[16];=20
char clothup[16];=20
char abdo[] =3D "skirt";=20
char abcer[] =3D "skirt";=20
char abon[] =3D "pants";=20
char abtre[] =3D "leather pants";=20
char abfor[] =3D "leather skirt";=20
char abcin[] =3D "magic pants";=20
char abses[] =3D "magic skirt";=20
char absep[] =3D "armor pants";=20
char upcer[] =3D "body";=20
char upon[] =3D "shirt";=20
char updo[] =3D "jacket";=20
char uptre[] =3D "leather jacket";=20
char upfor[] =3D "armor plate";=20
char upcin[] =3D "leather armor";=20
char upsis[] =3D "armor";=20
char upsep[] =3D "magic armor";=20
srand(time(NULL));=20
strenght =3D 0;=20
while(strenght =3D=3D 0){ /*decides if there will be more fights
###first###*/=20
printf("Choose the character you want to control, first the genre, 0 for
female, 1 for male.\n");=20
scanf("%d", &genre);=20
printf(" And the name, no more of 19 letters.\n");=20
scanf("%s", name);=20
printf("Now choose the height,\n");=20
scanf("%d\n", &tall);=20
printf("and then choose the weight\n");//THESE TWO LINES CHANGE THE
ORDERING!!!!! =20
=20
The above style of comment is not ANSI C90 compliant.
=20
=20
=20
scanf("%d\n", &weight);=20
printf("choose the belt radius\n");=20
scanf("%d\n", &radius);=20
printf("Choose muscle/bone proportion\n");=20
scanf("%d\n", &prop);=20
printf ("your character is a ");=20
if (genre =3D=3D 0)=20
printf("female ");=20
else=20
printf ("male ");=20
/*if((prop >=3D 33) || (prop < 15)){ /*stablish a bone proportion if
the set by the player is unacceptable*/=20
=20
=20
Above you begin a comment and inside it another comment which ends at
the same line. The */ terminator terminates the first /*. So you think
you have commented all the block below while you did not!=20
=20
=20
prop =3D rand() % 5;=20
if(prop =3D=3D 0)=20
prop =3D 20;=20
else=20
if(prop =3D=3D 1)=20
prop =3D 23;=20
else=20
if(prop =3D=3D 2)=20
prop =3D 25;=20
else=20
if(prop =3D=3D 3)=20
prop =3D 28;=20
else=20
prop =3D 30;=20
} */ =20
=20
Nope, the above */ closes nothing and is a syntax error.
=20
=20
So here are the bugs i discovered witg a quick pass. Bad use of
comments, and REMOVE those \n and commas from scanf(). After you do the
above, resend the fixed code.
=20
=20
=20
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
<http://www.noicys.cjb.net/>=20
* Alternative URL: http://run.to/noicys
|