Skip to content

Have ChatGPT inspect compilable programs for logic errors. #10

@Beliavsky

Description

@Beliavsky

Write a program that first verifies that a code compiles without warnings or errors, fixing it if necessary to resolve them, and then asks if the program is "good". If a problem is found and a new code is generated, present that to the user. Otherwise shorten the ChatGPT to response to "code is good". Some semantic analysis needs to be done -- look for "is good" in the response of ChatGPT, especially in the last sentence. For example, with instruction

If there is something wrong with the following Fortran code, fix it. Otherwise say it is "good".

program main
! compute a factorial
implicit none
integer :: i, ifac=0, n = 5
do i=2,n
   ifac = ifac*i
end do
print*,n," factorial equals ",ifac
end program main

ChatGPT-3 said

The Fortran program you provided has an issue with the initialization of the ifac variable. Since you want to compute the factorial, the initial value of ifac should be set to 1 instead of 0.

Here's the corrected version of your program:

program main
  implicit none
  integer :: i, ifac = 1, n = 5
  do i = 2, n
    ifac = ifac * i
  end do
  print *, n, " factorial equals ", ifac
end program main

If that code is presented to ChatGPT-3 with the same instruction, ChatGPT-3 says

The Fortran code you provided appears to be correct and does not have any errors. It computes the factorial of a given number n using a do loop and prints the result. So, the code is "good" as it stands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions