why c++ given different answer

when is calculate manually using calculator 365.25 x 2009 = 733787.25
but when in c++ the answer is 12891. why it be like that and how i can get answer using c++ is 733787.25 .......pls help me

this my coding:

#include <math.h>
#include <iostream.h>

main()
{

int dd,mm,yyyy,mmN,yyyyN,B,A,C,D,Cc;
char cal;
const double pi = 3.1415926535897932384626433832795 ;
double JD;

cout << "\n Date of Observation [ddmmyyyy]: ";
cin >> dd >> mm >> yyyy;

if ( dd >= 15 && mm >= 10 && yyyy >= 1582 ) goto cal;

cal:
if (mm <= 2)
{
yyyyN = yyyy - 1;
mmN = mm + 12;

cout << "\n\n yyyy'= " << yyyyN;
cout << "\n\n mm'= " << mmN;

A = yyyyN / 100;
B = 2 - A + (A/4);
cout << "\n A = " << A;
cout << "\n B = " << B;
C = 365.25 * yyyyN ;
cout << "\n C = " << C;
D = 30.6001 * ( mmN + 1 );
cout << "\n D = " << D;
JD = B + C + D + dd + 1720994.5;
cout << "\n Julian Day = " << JD;
}

return 0;
}
A = yyyyN / 100;
and
B = 2 - A + (A/4);
and
C = 365.25 * yyyyN ;
and
D = 30.6001 * ( mmN + 1 );

Might have something to do with it, considering that all those variables are ints. I recommend you try doubles, and remember to add decimal points to any numbers that don't have them when you change.

EDIT: Oh, and you never use pi. Wonder why?

-Albatross
Last edited on
It seems that you mean that you fill in 2010 in yyyy and get 2009 in yyyN.
C = 365.25 * yyyyN ;
(just like albatros said)

First of all, the outcome that you expect, 733787.25, could not be hold in an int variable, like C. You might want to declare C as a double or float.
Second of all, I don't remember the order in which the number should be converted with arithmetic operations between integral and non-integral types, but at least on this example you will have lost of precision anyway ;P.
thank you to all my friend...i success solve this problem......before that what function 'float'
Topic archived. No new replies allowed.