Re: NEWBIE: Code, C question.

From: Jeeves (philipe@basix.com)
Date: 05/12/96


Fionn Colvin wrote:
> 
> Hi all,
>        Below is the code for a function I am trying to write to
> substitute words for numbers, and its implimentation into my do_score
> command. Can someone tell me why it doesn't work? I tryed it with a char I
> made with str: 17 dex: 25 and con: 12. When I typed score it came back with
> str: pathetic  dex: pathetic  con: pathetic. :(
> 
> char *see_good(int current, int total)
> {
>   int percent;
>   static char word[256];
> 
>   if ((total == 200) && (current < 0))
>     current = 100 - current;
> 
>   if (total < 1)
>     total = 1;
> 
>   percent = (current / total) * 100;
> 
>   if (percent < 1)
>     percent = 1;
> 
>   if (percent >= 100)
>     strcpy(word, "supreme");
>   else if (percent >= 90)
>     strcpy(word, "excellent");
>   else if (percent >= 80)
>     strcpy(word, "very good");
>   else if (percent >= 70)
>     strcpy(word, "good");
>   else if (percent >= 60)
>     strcpy(word, "above average");
>   else if (percent >= 50)
>     strcpy(word, "average");
>   else if (percent >= 40)
>     strcpy(word, "below average");
>   else if (percent >= 30)
>     strcpy(word, "fair");
>   else if (percent >= 20)
>     strcpy(word, "poor");
>   else if (percent >= 10)
>     strcpy(word, "bad");
>   else
>     strcpy(word, "pathetic");
> 
>   return (word);
> }
> 
> ACMD(do_score)
> {
> /*  struct time_info_data playing_time;
>     struct time_info_data real_time_passed(time_t t2, time_t t1); */
> 
>   sprintf(buf, " Name: %s\r\n", GET_NAME(ch));
> 
>   sprintf(buf, "%s Title: %s\r\n", buf, GET_TITLE(ch));
> 
>   sprintf(buf, "%s\r\n", buf);
> 
>   sprintf(buf, "%s Race: %s\r\n", buf, RACE_ABBR(ch));
> 
>   sprintf(buf, "%s Level: %d                  Class: %s\r\n",
>           buf, GET_LEVEL(ch), CLASS_ABBR(ch));
> 
>   sprintf(buf, "%s Hit Points: %d(%d)         Mana: %d(%d)       Moves: %d(%d)\r\n",
>           buf, GET_HIT(ch), GET_MAX_HIT(ch), GET_MANA(ch), GET_MAX_MANA(ch),
>           GET_MOVE(ch), GET_MAX_MOVE(ch));
> 
>   sprintf(buf, "%s Age: %d years old.         Height: %d''         Weight: %d lbs\r\n",
>           buf, GET_AGE(ch), GET_HEIGHT(ch), GET_WEIGHT(ch));
> 
>   sprintf(buf, "%s Str: %s/%d                 Dex: %s              Con: %s\r\n",
>           buf, see_good(GET_STR(ch), 25), GET_ADD(ch), see_good(GET_DEX(ch), 25), see_good(GET_CON(ch), 25));
> 
>   sprintf(buf, "%s Int: %d                    Wis: %d              Cha: %d\r\n",
>           buf, GET_INT(ch), GET_WIS(ch), GET_CHA(ch));
> 
>   sprintf(buf, "%s AC: %d                     Hit Roll: %d         Damage Roll: %d\r\n",
>           buf, GET_AC(ch), GET_HITROLL(ch), GET_DAMROLL(ch));
> 
> Thanks in advance
> 
> Fionn

I might very well be completely insane and unfit to answer this question, but 
have you tried taking out all of the 'else' keywords? When I was coding my 
stat selection method (which is by ability score modification with points), 
it did sort of the same thing, printing only the results of the last 
statement in the if tree. This is all about as clear as mud (no pun 
intended), I know, but just try it. And if anyone else knows more than me (as 
I suspect they do), they really ought to answer. And if you think I was 
inebriated when I coded my stat selector, flame me at <philipe@basix.com>. 
:)

-- Jeeves
Creator/Imp/Builder of CalaisMUD (under development)



This archive was generated by hypermail 2b30 : 12/18/00 PST