1 Replies - 1624 Views - Last Post: 04 October 2006 - 07:58 AM Rate Topic: -----

#1 jaclyn_85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 16-September 06

Converting a Double to an Integer

Posted 03 October 2006 - 06:02 PM

In order for the last part of my calculations to work, starting with lc = jdn;
i need to first conver jdn which is a double into an integral type, but am not sure how to do this... please help.

#include <stdio.h>

int main()
{
double jdn, tm;
   long lc, nc, ic, jc;
   int day, month, year, hours, minutes, seconds, a, b, meridian;



 /*print title*/

 printf(" * * Julian Date Conversion * *\n");

 /*ask user for a Julian date */

 printf ("Please enter a Julian Date:\n");
 scanf("%lf", &jdn);

if (jdn <= 2299160)
  printf ("Error: You have entered an invalid number.");

/* Perform calculations */
   lc = jdn + 68569;
   nc = 4 * lc / 146097;
   lc = lc - (146097 * nc + 3) / 4;
   ic = 4000 * (lc + 1) / 1461001;
   lc = lc - 1461 * ic / 4 + 31;
   jc = 80 * lc / 2447;
   day = lc - 2447 * jc / 80;
   lc = jc / 11;
   month = jc + 2 - 12 * lc;
   year = 100 * (nc - 49) + ic + lc;


   lc = jdn;
   tm = jdn - lc;
   hours= jdn * 24;
   a= jdn % 60;
   minutes= a * 60;
   b= minutes % 60;
   seconds= b * 60;

if (meridian >= 12)
	 printf ("p.m.");
else printf ("a.m.");

/* print date*/

   printf("%d %d %d %d %d %d %d\n", month, day, year, hours, minutes, seconds,
		  meridian);
   return 0;
}


This post has been edited by jaclyn_85: 03 October 2006 - 07:16 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Converting a Double to an Integer

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Converting a Double to an Integer

Posted 04 October 2006 - 07:58 AM

Are you speaking of integrals, or integers? You've mentioned both. If the answer is integers, dou you need to round the double to the nearest integer, or simply truncate?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1