|
From: Carlos d. M. <cg...@wo...> - 2002-08-07 18:48:34
|
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?
There are two lines, in red, that invert their order, the scanf is done
before its printf.
printf("and then choose the weight\n");//THESE TWO LINES CHANGE THE
ORDERING!!!!!
scanf("%d\n", &weight);
You see (adding two lines before)
___________________________________
| Title _0X |
|-----------------------------------------------|
| [...] |
| Choose the height. |
| 180 |
| _ |
|___________________________________|
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...
___________________________________
| Title _0X |
|-----------------------------------------------|
| Choose the height. |
| 180 |
| 80 |
| And then choose the weight |
|___________________________________|
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.
Copying the scanf after the printf and having two scanf only makes the
error repeat in the next pair printf/scanf
The best is that it happens when I compile it with borland 5.5.
/*a text-based fighting game*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int genre, level, answ, result, end, weight, tall, radius, prop, pula;
int vic, mvic, round, mov, mmov, posa, posb, posc, posd, pose, monster,
hit;
int agil, magil;
int a, u;
int difab, difup, difpta, difptb;
int strenght;
int abwer, upwer, piwer, mawer, cabwer, arwer;
int mabwer, mupwer, mpuiwer, mmawer, mcabwer, marwer;
int atpts, dfpts, agpts, witpts, velpts, dampts, sufpts, respts;
int matpts, mdfpts, magpts, mwitpts, mvelpts, mdampts, msufpts, mrespts;
int oat, odf, oag, owit, ovel, odam, ores;
char name[20];
char wear[16];
char clothab[16];
char clothup[16];
char abdo[] = "skirt";
char abcer[] = "skirt";
char abon[] = "pants";
char abtre[] = "leather pants";
char abfor[] = "leather skirt";
char abcin[] = "magic pants";
char abses[] = "magic skirt";
char absep[] = "armor pants";
char upcer[] = "body";
char upon[] = "shirt";
char updo[] = "jacket";
char uptre[] = "leather jacket";
char upfor[] = "armor plate";
char upcin[] = "leather armor";
char upsis[] = "armor";
char upsep[] = "magic armor";
srand(time(NULL));
strenght = 0;
while(strenght == 0){ /*decides if there will be more fights
###first###*/
printf("Choose the character you want to control, first the genre, 0 for
female, 1 for male.\n");
scanf("%d", &genre);
printf(" And the name, no more of 19 letters.\n");
scanf("%s", name);
printf("Now choose the height,\n");
scanf("%d\n", &tall);
printf("and then choose the weight\n");//THESE TWO LINES CHANGE THE
ORDERING!!!!!
scanf("%d\n", &weight);
printf("choose the belt radius\n");
scanf("%d\n", &radius);
printf("Choose muscle/bone proportion\n");
scanf("%d\n", &prop);
printf ("your character is a ");
if (genre == 0)
printf("female ");
else
printf ("male ");
/*if((prop >= 33) || (prop < 15)){ /*stablish a bone proportion if
the set by the player is unacceptable*/
prop = rand() % 5;
if(prop == 0)
prop = 20;
else
if(prop == 1)
prop = 23;
else
if(prop == 2)
prop = 25;
else
if(prop == 3)
prop = 28;
else
prop = 30;
} */ /*closes the stablishment of a
correct bone proportion*/
printf("called %s, of %d centimeters and %d kilogrames, with a
muscle-bone proprotion of %d, and belt radius of %d. So, your character
is ", name, tall, weight, prop, radius);
if ((prop <= 32) && (prop > 29))
printf("very strong ");
else
if ((prop <= 29) && (prop > 27))
printf("strong ");
else
if((prop <=27) && (prop > 22))
printf("normal in strenght ");
else
if((prop <= 22) && (prop > 14))
printf("weak ");
if(weight > (tall - 85)){
if(genre == 0)
printf("his/her size is only appearance ");
else
printf("his/her size is only appearance ");
}
else
if(prop <= 10){
printf("very weak ");
if(weight > (tall - 85))
printf("the mass is evidently uncompetent");
}
agil = (tall - weight + 100) - (radius / 2) + 70;
if(agil > 250)
printf("and very agile\n");
else
if((agil <= 250) && (agil > 235))
printf("and agile\n");
else
if((agil <= 235) && (agil > 215))
printf("and normal in agility\n");
else
if((agil <= 215) && (agil > 200))
printf("and slow\n");
else
if(agil <= 200)
printf("and completely lack of reflex\n");
printf("You can choose the next wearings:\n");
printf("Feet wearing: shoes, 1; boots, 2; long boots, 3; armor boots,
4.\n");
scanf("%d\n", &piwer);
printf("Legs wearing: pants, 1; skirt, 2; leather pants, 3; leather
skirt, 4; magic pants, 5; magic skirt, 6; armour pants, 7.\n");
scanf("%d\n", &abwer);
switch(abwer){
case 0:
strcpy(clothab, abcer);
break;
case 1:
strcpy(clothab, abon);
break;
case 2:
strcpy(clothab, abdo);
break;
case 3:
strcpy(clothab, abtre);
break;
case 4:
strcpy(clothab, abfor);
break;
case 5:
strcpy(clothab, abcin);
break;
case 6:
strcpy(clothab, abses);
break;
case 7:
strcpy(clothab, absep);
break;
}
printf("Body wearing: shirt, 1; jacket, 2; leather jacket, 3; armor
plate, 4; leather armor, 5; armor, 6; magic armor, 7.\n");
scanf("%d\n", &upwer);
switch(upwer){
case 0:
strcpy(clothup, upcer);
break;
case 1:
strcpy(clothup, upon);
break;
case 2:
strcpy(clothup, updo);
break;
case 3:
strcpy(clothup, uptre);
break;
case 4:
strcpy(clothup, upfor);
break;
case 5:
strcpy(clothup, upcin);
break;
case 6:
strcpy(clothup, upsis);
break;
case 7:
strcpy(clothup, upsep);
break;
}
printf("Head wearing: nothing, 1; hat, 2; helmet, 3;whole helm, 4.\n");
scanf("%d\n", &cabwer);
printf("Hand wearing: nothing, 1; glovers, 2; armor glovers, 3; armed
glovers, 4.\n");
scanf("%d\n", &mawer);
printf("weapon: none, 1; knife, 2; bar, 3; long bar,4; articulate bars,
5;bow, 6; long bow, 7; little axe, 8; big axe, 9; axe and net, 10; short
sword, 11; long sword, 12; sword and shield, 13;.\n");
scanf("%d", &arwer);
atpts = ((arwer + 1) * 30) + ((prop -15) * 40) + ((piwer + 1) * 50);
dfpts = ((agil) * 2) + ((abwer +1) * 15) + ((piwer +1) * 5) + ((cabwer
+1) * 150) + ((upwer +1) * 300) - (radius - 80);
if((arwer == 9) || (arwer == 10) || (arwer >= 12))
dfpts = dfpts + (arwer * 8);
else
dfpts = dfpts + (arwer * 3);
witpts = (rand() % 50) + 80;
velpts = (agil) * tall / weight;
dampts = (atpts / 2) + ((atpts * prop) / (agil));
respts = (((dfpts * velpts) / weight) + (atpts / witpts) + (agil * 10))
/ (weight / 4);
sufpts = (rand() % 10) + 2;
printf("attack points = %d\n defense points = %d\n wits points = %d\n
velocity points = %d\n damage points = %d\n resistence points = %d\n
suffering points = %d\n", atpts, dfpts, witpts, velpts, dampts, respts,
sufpts);
round = 0;
ores = respts;
ovel = velpts;
odam = dampts;
owit = witpts;
oat = atpts;
odf = dfpts;
a = abwer;
u = upwer;
difab = 0;
difup = 0;
difpta = (abwer * 15) / dfpts;
difptb = (upwer * 300) / dfpts;
printf("press 0 if you want to play again\n");
scanf("%d", &strenght);
} /*##first##*/
return 0;
}
P.S.- Sorry for my firsts shaming posts at this list, a year ago, more
or less, I regret having written so big stupidities, as I wrote those
couple of messages. Forgive me and forget them. (Yeah, I know, this line
should be in an older message, when the referenced messages were
remembered).
Thank you all
|