Re: NEWBIE: Code, C question.

From: Mark McArthey (mcarthey@mfa.com)
Date: 05/14/96


Fionn, 

The problem is that your values current and total are int.  When you 
do the division in the line:

	percent = (current / total) * 100;

You get a result of 0 and then multiply that by 100 which, of course, 
is also 0.  Yep, that's pretty pathetic for a stat score.  ;)

Later!


On Mon, 13 May 1996, 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
> 



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