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 36 37 38 39 40 41 42 43 44
|
#include <stdio.h>
#include <stdlib.h>
int main () {
int JD, m, d, dAno;
char noon;
printf ("This program gives the Julian Date for Jan-Feb 2014\nEnter the month number: \n");
scanf("%d", &m);
while ((m>2)||(m<1)) {printf ("Error; this program only applies\nto January or February \n");
printf ("Enter the month number: \n");
scanf("%d", &m);}
printf ("Now enter the day of the month:\n");
scanf("%d", &d);
while ((d>31)||(d<1)) {printf ("Error; you must enter a valid date \n");
printf ("Now enter the day of the month:\n");
scanf("%d", &d);}
printf ("Do you want the Julian Date after or before noon in Greenwich?\nType A or B:");
scanf("%d", &noon);
/*My first difficulty here: how can I evaluate a char? How can I assure that
if the user types a different letter, signal or number the program says he's
wrong, like above? Like, if I type a decimal or a char for the month, it enters in
infinite looping, can I prevent that happening?*/
if (m=1){
dAno=d;
JD=dAno+2456658;
printf ("The Julian Date is %d\n", JD);}
else{
if (m=2){
dAno=d+31;
JD=dAno+2456658;
printf ("A Data Juliana eh %d\n", JD);}}
/*Here I have the main problem: the program is working well for January,
but if I want to calculate for February, it simply ignores and calculates
like if it was still January: Feb 1st returns 2456659, just like
it was Jan 1st. I can't handle with these "ifs" and "elses" and also I
can't make the proper use of the "noon" flag - if noon = B, the Julian Date shall
be decremented by 1. At least the program compiles, that's already a deed for me.
I'm using only the 1st two months for testing, I want to make a complete
script for all the 12 months, but I need some tip about how to do that
in a more efficient way*/
system ("PAUSE");
return 0;
}
|