FORTRAN 90 Help- reading input in format DDMMYYYY + more

In summary, the conversation discusses an assignment on FORTRAN 90 where the task is to enter a date in DDMMYYYY format and compute and display the day of the week it falls on using a given algorithm. The student was able to code a program that worked in the format of date, month, year with commas, but struggled to make it work without the commas. The solution involves using a formatted input and left justifying the date. For part 2 of the assignment, the student is asked to use the program to determine the day of the week their birthday falls on and find the next five times their birthday falls on that same day of the week. They are unsure of how to approach this but know they will need to use a
  • #1
cooljosh2k2
69
0

Homework Statement



This is assignment is on FORTRAN 90:

In an assignment i have, i am to enter a date in the format DDMMYYYY, and its suppose to compute and display the day of the week that date falls on (based on a given algorithm). I was able to code a program that would give me the right day of the week, however, i was only able to get it to work in the format: date, month, year (with commas separating each of them). How can i get my program to read the date DDMMYYYY, without the commas.

For part 2, i am to use the program to determine the day of the week my birthday falls on, then i should find the next five times (after 2011) that my birthday falls on that same day of the week.

The Attempt at a Solution



For part 1, this is what i did:

-----------------------------------------------------

PROGRAM assignment2
IMPLICIT NONE

INTEGER:: Day, Month, Year, Century, H

READ(*,*) Day,Month,Year !to read in format DD,MM,YYYY

Month = Month -2
!this accounts for unusual format for months (eg. March=01...February=12)
If (Month <= 0) Month = Month + 12
IF (Month >= 11) Year = Year - 1
Century = INT(Year / 100)
!eg. 2011 = 20
Year = MOD(Year, 100)
!eg. 2011= 11
H = INT(13 * Month - 1)/5 + Day + Year + &
(Year / 4) + (Century / 4) - 2*Century
H = MOD(H,7)
IF (MOD(H,7) < 0) H = MOD(H,7) + 7
!this will make sure our day of the week is a positive integer
write(*,*) 'Day Of the Week :',HEND PROGRAM assignment2

---------------------------------------------

For part 2, i am completely lost. I understand that i will need to do a DO LOOP, but have no idea what to do.

Please help.

Thanks
 
Physics news on Phys.org
  • #2
If I am understanding you correctly regarding your comma question, you could use a formatted input.

integer dd,mm,yyyy

read(5,100)dd,mm,yy
100 format(2i2,1i4)

Thus February 4, 1977 would be entered as: 04021977. It would have to be left justified. The 5 in the format statement means it is reading from keyboard input. It won't work unless it is left justified.


100 format(2i2,1i4)
 

FAQ: FORTRAN 90 Help- reading input in format DDMMYYYY + more

What is FORTRAN 90 and how does it differ from previous versions?

FORTRAN 90 is a high-level programming language used for scientific and engineering applications. It is an updated version of FORTRAN, which was first developed in the 1950s. FORTRAN 90 introduced new features such as modules, pointers, and dynamic memory allocation, making it more powerful and easier to use than its predecessors.

How do I read input in the format DDMMYYYY in FORTRAN 90?

To read input in the format DDMMYYYY, you can use the READ statement with the DATE_AND_TIME intrinsic function. This function allows you to specify the format of the input string, in this case 'DDMMYYYY', and then converts the input into separate variables for day, month, and year.

Can I read input in other formats besides DDMMYYYY in FORTRAN 90?

Yes, FORTRAN 90 has various input formats that can be specified using the READ statement. These include 'MM/DD/YYYY', 'YYYY-MM-DD', and 'DD-MMM-YYYY', among others. You can also define your own custom formats using the FMT keyword.

How can I read multiple input values in FORTRAN 90?

To read multiple input values, you can use the READ statement with a list of variables separated by commas. For example, READ(1,*) day, month, year will read the input values for day, month, and year into their respective variables.

Can I read input from a file in FORTRAN 90?

Yes, FORTRAN 90 has built-in file handling capabilities that allow you to read input from a file. You can use the OPEN statement to open a file, and then use the READ statement to read input from the file into your program variables.

Similar threads

Replies
2
Views
8K
Replies
4
Views
3K
Replies
12
Views
2K
Replies
5
Views
2K
Replies
6
Views
5K
Replies
7
Views
2K
Back
Top