Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

fortran counting vowels (each and total) PROGRAM countingvowels ! Program to pro

ID: 3760498 • Letter: F

Question

fortran counting vowels (each and total)

PROGRAM countingvowels

! Program to provide a count for each and total vowels.
! Program to read a string and count the vowels.
! Vowels (“a”, “e”, “i”, “o”, and “u”).
! vowels should be counted for both upper and lower-case.
! Assume the input string may be no longer than 1000 characters.

! declare variables

implicit none

INTEGER :: i, Vowels=0
CHARACTER(80) :: Line

!---------------------------
! Display initial header
WRITE (*,'(a,/)') "Count for each and total vowels"

!----------------------------
! Prompt for string
! read string
WRITE (*,'(a)',advance="no") "Enter String (80 char max): "
READ (*,'(a)') Line

!----------------------------
! loop
DO I = 1, len (Line)
  
  SELECT CASE (Line (I:I))
  CASE ('A','E','I','O','U', &
   'a','e','i','o','u')
  Vowels = Vowels + 1

  END SELECT

END DO

!-----------------------------
! display final string

WRITE (*,'(/,a)') "------------------------------------"
WRITE (*,'(a,/,2x,a,/)') "Vowels: ", Vowels

END program countingvowels

I have done this so far, please fix this can count (each and total) vowels

Explanation / Answer

implicit none

INTEGER :: i, Vowels=0,a=0,e=0,i=0,o=0,u=0
CHARACTER(80) :: Line

!---------------------------
! Display initial header
WRITE (*,'(a,/)') "Count for each and total vowels"

!----------------------------
! Prompt for string
! read string
WRITE (*,'(a)',advance="no") "Enter String (80 char max): "
READ (*,'(a)') Line

!----------------------------
! loop
DO i = 1, len (Line)
    if(Line(i:i) == 'a' .or. Line(i:i) == 'A' ) then

  a=a+1

Endif

if(Line(i:i) == 'e' .or. Line(i:i) == 'E' ) then

  e=e+1

Endif

if(Line(i:i) == 'i' .or. Line(i:i) == 'I' ) then

  o=o+1

Endif

if(Line(i:i) == 'o' .or. Line(i:i) == 'O' ) then

  o=o+1

Endif

if(Line(i:i) == 'u' .or. Line(i:i) == 'U' ) then

  u=u+1

Endif


  Vowels = a+e+i+o+u
endif

END DO

!-----------------------------
! display final string

WRITE (*,'(/,a)') "------------------------------------"

WRITE (*,'(a,/,2x,a,/)') "No of Vowels A : ", a

WRITE (*,'(a,/,2x,a,/)') " No of Vowels E : ", e

WRITE (*,'(a,/,2x,a,/)') " No of Vowels I: ", i

WRITE (*,'(a,/,2x,a,/)') " No of Vowels O ", o

WRITE (*,'(a,/,2x,a,/)') " No of Vowels U : ", u
WRITE (*,'(a,/,2x,a,/)') "Vowels: ", Vowels

END program countingvowels