You are on page 1of 2

program CGPA_Calculator

implicit none

! Constants
integer, parameter :: numStudents = 3
integer, parameter :: numCourses = 9

! Variables
real :: percentage
integer :: i, j
real, dimension(numStudents, numCourses) :: grades
real, dimension(numStudents) :: cgpa

! Input grades for each student


do i = 1, numStudents
write(*,*) 'Enter grades (percentage) for Student ', i
do j = 1, numCourses
write(*,*) 'Enter grade for Course ', j, ': '
read(*,*) grades(i, j)
end do
end do

! Calculate CGPA for each student


do i = 1, numStudents
cgpa(i) = 0.0
do j = 1, numCourses
select case (int(grades(i, j) * 10)) ! Convert to integer for case matching
case (90:100)
cgpa(i) = cgpa(i) + 4.0
case (80:89)
cgpa(i) = cgpa(i) + 3.0
case (70:79)
cgpa(i) = cgpa(i) + 2.0
case (60:69)
cgpa(i) = cgpa(i) + 1.0
case default
! Grade less than 60.0, no additional points
end select
end do

! Calculate average CGPA


cgpa(i) = cgpa(i) / real(numCourses)
end do
! Output CGPA for each student
do i = 1, numStudents
write(*,*) 'CGPA for Student ', i, ': ', cgpa(i)
end do

end program CGPA_Calculator

You might also like