Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have ChatGPT inspect compilable programs for logic errors. #10

Open
Beliavsky opened this issue Jul 1, 2023 · 0 comments
Open

Have ChatGPT inspect compilable programs for logic errors. #10

Beliavsky opened this issue Jul 1, 2023 · 0 comments

Comments

@Beliavsky
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant