From: Mark Brown Newsgroups: comp.lang.c,comp.os.msdos.djgpp Subject: Re: having trouble with long numbers Followup-To: comp.lang.c Date: 31 Jul 1997 23:15:52 +0000 Organization: Bah! Organization? Lines: 58 Sender: broonie AT unknown DOT localdomain Message-ID: References: <01bc9c51$0ceeec80$78ed1fcc AT darkstar> NNTP-Posting-Host: dialup-87.publab.ed.ac.uk Mime-Version: 1.0 (generated by tm-edit 7.102) Content-Type: text/plain; charset=ISO-8859-1 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Content-Transfer-Encoding: 8bit Precedence: bulk "Michèle C. Dupré" 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 > > 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; > }