NEWBIE: Code, C question. [Part 2] (fwd)

From: Billy H. Chan (bhchan@crane.CS.Berkeley.EDU)
Date: 05/12/96


From: Fionn Colvin <fcolvin@metz.une.edu.au>

       Ok, I changed my percent line to:

       percent = (100 * current) / total

You might want to fire up old gdb and do something like the following:

b <function name>
run
(when you hit the break point...)
step    (keep steping until you hit the line above)
print current
print total
step
print percent

That should give you some better feel for what's happening around
this point... have fun... gdb's your friend.

Another thing to check is whether you're using the right values or
if you're sending the same number for str/dex/con... 

The if (total...) current == ...  block also seems fishy to me.  What's
so special about total == 200?  and why assume 100 - <negative current>
will give a good result (a negative current would end up as 100 + 
abs(current) in what you have...  (you might just do a simple MAX(0, current)
and keep negatives out.)
-- Billy  H. Chan     bhchan@po.eecs.berkeley.edu  bhchan@csua.berkeley.edu
   CogSci/CompSci     http://www.csua.berkeley.edu/~bhchan     ResumeInside

APPENDED IS THE FUNCTION:

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 * 100) / total;

  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