Mail Archives: djgpp/1997/08/04/19:09:05
"Michèle C. Dupré" <forbinky AT ix DOT netcom DOT com> writes:
> I want to be able to have more than 10 digits print out (if the age were
> 10,000 years for example).
You want a variable capable of holding 10,000? The include file
limits.h defines the maximum values of various data types (among other
things). These must be at least the values specified in the
standard. For example, INT_MAX, the maximum integer value, must be at
least 32767. So this would hold 10,000 years OK.
> Also can someone direct me to the FAQ(so that I can RTFM)?
It can be ftped from rtfm.mit.edu in pub/usenet/comp.lang.c/ and found
on the web at http://www.eskimo.com/~scs/C-faq/top.html . Most
newsgroup FAQs can be ftped from rtfm.mit.edu.
> #include <stdio.h>
> int main()
> int daysper, daystotal, secondsperday, years;
> long long totalseconds;
> daysper = 365;
> secondsperday = 86400;
These could be replaced by macros. For example
#define DAYS_PER 365
#define SECONDS_PER_DAY 86400
As you say below, this won't be completely accurate. There are leap
years to consider.
> printf("My second handmade program!\n\nTo tell you the number of seconds
> (estimate) you have lived.\n\n");
This would be easier to read as seperate lines. Also, you could use
puts() to print the text.
> printf("Enter your age in years: ");
fflush(stdout) would ensure that this gets written to screen. On some
implementations output is written a line at a time, and the prompt
wouldn't appear until the user typed return. fflush() is used on an
output stream (file) to ensure that everything that has been written
to it has been sent to the operating system.
> scanf("%d", &years);
> daystotal=(daysper * years);
> printf("Total days = %d\n\n", daystotal);
> totalseconds=(daystotal * secondsperday);
> printf("The total number of seconds is: %i\n",totalseconds);
> return 0;
- Raw text -