Julian day calculator

I am getting odd compile errors like (in dev C++)
Line 30: stray \215 in program
Line 30: 12 cannot be used as a function
Line 31: expected ';' before ToD
I have no idea what these compile errors mean.
Here is my code:





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "std_lib_facilities.h" // includes the libraries: iostream, fstream, sstream, cmath, cstdlib, string, vector, algorithm, stdexcept
#define new '\n' // defines (the already key word) new to make a new line
using namespace std; 
double M,Y,D,MN,H,S,JDN,TOD; //M = months Y = years D = days MN = minutes H = hours S = seconds JDN = Julian Day Number
// JDN = Julian date number ToD = Time of day... 
int main() // start main 
{
    cout << "Age calc" << new;
    cout << new; // new line
    cout << "The day You were born" << new;
    cout << new;
    cin >> D; // input day
    cout << "The Month You were born" << new;
    cin >> M; // input month 
    cout << "The Year You were born" << new;
    cin >> Y; // input year
    cout << "The Hour You were born" << new;
    cout << new;
    cin >> H; // input hour 
    cout << "The Minute You were born" << new;
    cin >> MN; // input minute
    cout << "The Second You were born" << new;
    cin >> S; // input second
    cout << new;  
    cout << new;
    



JDN = (1461 * (Y + 4800 + (M - 14)/12))/4 +(367 * (M - 2 - 12 × ((M - 14)/12)))/12 - (3 * ((Y + 4900 + (M - 14)/12)/100))/4 + D - 32075 // julian day number algorithm
TOD = JDN + ((H-12)/24) + (MN/1440) + (S/86400) // JDN to JD algorithm
cout << TOD << new; // should desplay the answer to the algorithm
system ("PAUSE"); // pause before exit
return 0;
} // end main 



and sorry for marking the previous topic solved

Your error on line 31 is because you missed the semicolon at line 30. Whenever you get a semicolon error check the line *before* the one it's on; that's usually where you missed it.
You still have a x sign in line 30. Make that an *. x is not an operator. As for that \215 it's probably because you have a backslash instead of a forward slash but I can't really find one.
The last error is probably because you put a double bracket pair after the number 12. I'm not sure where, you might want to try breaking that gigantic arithmetic statement into more manageable chunks for debugging purposes.
All those errors are easy to understand and they are in normal language. If you honestly can't figure them out you need to read more.
AND STOP USING THAT DEFINE. Change that to something else or use endl like real programmers do. (You could also use "\n" but endl flushes which is useful.) That's poor style, it's pointless, it's silly and you are using a language keyword - an operator for crying out loud. Just looking at that drives me nuts.
Also don't use dev, it's outdated, see this article: http://www.cplusplus.com/forum/articles/7263/
EDIT: Since you don't seem to know what endl is, it's a stream object that, when outputted, appends a newline and flushes the buffer.
So this code:
cout << "hello world" << endl;
Is like your code except it's actually acceptable programming.
Last edited on
The Error "stray \215 in program" is because you are using non ASCII characters ( which again is the × )
I think also "12 cannot be used as a function" refers to that, it discards the × and reads 12 ( /*...*/ )
fixed it



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "std_lib_facilities.h" // includes the libraries: iostream, fstream, sstream, cmath, cstdlib, string, vector, algorithm, stdexcept
/*defines (the already key word) new to make a new line *TAKEN OUT* */
using namespace std; 
double M,Y,D,MN,H,S,JDN,TOD; //M = months Y = years D = days MN = minutes H = hours S = seconds JDN = Julian Day Number
// JDN = Julian date number ToD = Time of day... 
int main() // start main 
{
    cout << "Age calc" << endl;
    cout << endl; // new line
    cout << "The day You were born" << endl;
    cout << endl;
    cin >> D; // input day
    cout << "The Month You were born" << endl;
    cin >> M; // input month 
    cout << "The Year You were born" << endl;
    cin >> Y; // input year
    cout << "The Hour You were born" << endl;
    cout << endl;
    cin >> H; // input hour 
    cout << "The Minute You were born" << endl;
    cin >> MN; // input minute
    cout << "The Second You were born" << endl;
    cin >> S; // input second
    cout << endl;  
    cout << endl;
    



JDN = (1461 * (Y + 4800 + (M - 14)/12))/4 +(367 * (M - 2 - 12 * ((M - 14)/12)))/12 - (3 * ((Y + 4900 + (M - 14)/12)/100))/4 + D - 32075; // julian day number algorithm
TOD = JDN + ((H-12)/24) + (MN/1440) + (S/86400); // JDN to JD algorithm
cout << TOD << endl; // should desplay the answer to the algorithm
system ("PAUSE"); // pause before exit
return 0;
} // end main 



EDIT: Is there any alternatives to system ("pause")? I know that uses the batch command pause which is really slow
and is there any way to make 2.4511e+066 as a actual number
Edit I used cout << setprecision(16);
Last edited on
wow first time i have used cin.get and it actually worked... thank you
Glad to be of assistance. I hope you got over that ridiculous stupid #define.
Last edited on
Topic archived. No new replies allowed.