- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am a beginner in Fortran and learning it from the book titled "Fortran For Scientists & Engineers" (2018 version) by Stephen Chapman. In page 200, the author provides an example regarding the formatting. I wrote the exact code in my IDE (Visual Studio 2019) and received these errors:
error #6899: error #6899 First non-blank character in a character type format specifier must be a left parenthesis
I'm suspecting it should be related to the project settings, but I'm not sure. How can I solve this issue?
Thanks in advance
I attached the code too...
PROGRAM capacitor
!
! Purpose:
! To calculate the behavior of a capacitor as follows:
! 1. If capacitance and voltage are known, calculate
! charge, number of electrons, and energy stored.
! 2. If charge and voltage are known, calculate capa-
! citance, number of electrons, and energy stored.
!
! Record of revisions:
! Date Programmer Description of change
! ==== ========== =====================
! 11/18/15 S. J. Chapman Original code
!
IMPLICIT NONE
! Data dictionary: declare constants
REAL, PARAMETER :: ELECTRONS_PER_COULOMB = 6.241461E18
! Data dictionary: declare variable types, definitions, & units
REAL :: c ! Capacitance of the capacitor (farads).
REAL :: charge ! Charge on the capacitor (coulombs).
REAL :: electrons ! Number of electrons on the plates of the capacitor
REAL :: energy ! Energy stored in the electric field (joules)
INTEGER :: type ! Type of input data available for the calculation:
! 1: C and V
! 2: CHARGE and V
REAL :: v ! Voltage on the capacitor (volts).
! Prompt user for the type of input data available.
WRITE (*, 100)
100 FORMAT (' This program calculates information about a ' &
'capacitor.',/, ' Please specify the type of information',&
' available from the following list:',/,&
' 1 -- capacitance and voltage ',/,&
' 2 -- charge and voltage ',//,&
' Select options 1 or 2: ')
! Get response and validate it.
DO
READ (*,*) type
IF ( (type == 1) .OR. (type == 2) ) EXIT
WRITE (*,110) type
110 FORMAT ('Invalid response: ', I6, '. Please enter 1 or 2:')
END DO
! Get additional data based upon the type of calculation.
input: IF ( type == 1 ) THEN
! Get capacitance.
WRITE (*,'Enter capacitance in farads: ')
READ (*,*) c
! Get voltage.
WRITE (*,'Enter voltage in volts: ')
READ (*,*) v
ELSE
! Get charge.
WRITE (*,'Enter charge in coulombs: ')
READ (*,*) charge
! Get voltage.
WRITE (*,'Enter voltage in volts: ')
READ (*,*) v
END IF input
! Calculate the unknown quantities.
calculate: IF ( type == 1 ) THEN
charge = c * v ! Charge
ELSE
c = charge / v ! Capacitance
END IF calculate
electrons = charge * ELECTRONS_PER_COULOMB ! Electrons
energy = 0.5 * c * v**2 ! Energy
! Write out answers.
WRITE (*,120) v, c, charge, electrons, energy
120 FORMAT ('For this capacitor: ',/, &
' Voltage = ', F10.2, ' V',/, &
' Capacitance = ', ES10.3, ' F',/, &
' Total charge = ', ES10.3, ' C',/, &
' Number of electrons = ', ES10.3,/, &
' Total energy = ', F10.4, ' joules' )
END PROGRAM capacitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The compiler is correct. When a format string is used inside as the FMT= specifier in a WRITE statement, the string has to begin and end with matching parentheses. Change
WRITE (*,'Enter charge in coulombs: ')
to
WRITE (*,'("Enter charge in coulombs: ")')
or
print *,'Enter charge in coulombs: '
and similarly for the other WRITE statements.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The compiler is correct. When a format string is used inside as the FMT= specifier in a WRITE statement, the string has to begin and end with matching parentheses. Change
WRITE (*,'Enter charge in coulombs: ')
to
WRITE (*,'("Enter charge in coulombs: ")')
or
print *,'Enter charge in coulombs: '
and similarly for the other WRITE statements.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much! It worked. I will report this issue to the author of the book.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page