delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/11/24/07:59:02

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Message-ID: <918AC92BEEE5D211AA2E00A024B984F1A89FC2@FSBV-NTSERVER>
From: "Budding, Gerben" <G DOT Budding AT fugro DOT nl>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>
Subject: RE: newbie C question
Date: Mon, 24 Nov 2003 12:52:47 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2657.72)
Reply-To: djgpp AT delorie DOT com

Keith,

Have a look at the ASCII table and you'll see that the digits 0-9 have ASCII
codes 0x30 - 0x39. The getchar() function will return the ASCII code of the
key just typed. If you subtract character zero (actually the ASCII code of
character zero) you will get the decimal digit in return: e.g. 0x37 - 0x30 =
7. 

There are several functions available to classify the ASCII codes returned
by getchar() e.g. isdigit(), isalpha(), islower(), isupper(). These might be
helpful to solve your problem.

good luck,

Gerben.

-----Original Message-----
From: Keith__ [mailto:asdth AT hotmail DOT com]
Sent: Monday, November 24, 2003 12:07 PM
To: djgpp AT delorie DOT com
Subject: newbie C question


Hi

sorry to bother you all with this but im currently at college beginning to
learn C. I have a question ive been given which i need to code and answer
but i just dont understand what it wants or how to do it. could someone
please help out?

heres the question in full:

1.              Read three single digit characters from the keyboard and
convert them into their numerical equivalent values (Hint: use getchar(),
subtract character zero from the digit character to convert it to its
numerical value.)





The program should test the digits and


a)    print an appropriate message if the digits are identical
b)    the average of the three digits
c)     the minimum of the three digits
d)    the maximum of the three digits
e)    the percentage value of the smaller number with respect to the larger.

Thanx

Keith

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019