For the most part, this works pretty good. I see it as good tool that will save me time.
I asked:
In powerbasic console compiler v6, I have a string variable "starttime" with looks like this "08:00 PM" and I have a numeric value called "totalMinutes". Write the code to add the minutes to 08:00 PM and and show an end time. For instance, if startTime="08:00 PM" and total minutes=90, I want a function that would return "09:30 PM
and it replied:
In PowerBASIC Console Compiler v6, you can create a function to add the minutes to the start time and return the end time as follows:
Now you can use this function to add minutes to a given start time:
I'm mostly impressed by how it understood my question.
Yes, I could have figured this out myself but I think it's a fine illustration on AI's usefulness in programming.
I asked:
In powerbasic console compiler v6, I have a string variable "starttime" with looks like this "08:00 PM" and I have a numeric value called "totalMinutes". Write the code to add the minutes to 08:00 PM and and show an end time. For instance, if startTime="08:00 PM" and total minutes=90, I want a function that would return "09:30 PM
and it replied:
In PowerBASIC Console Compiler v6, you can create a function to add the minutes to the start time and return the end time as follows:
Code:
FUNCTION AddMinutesToTime(BYVAL startTime AS STRING, BYVAL totalMinutes AS LONG) AS STRING LOCAL hour, minute AS LONG LOCAL isPM AS STRING ' Extract hour, minute and AM/PM from the input string hour = VAL(LEFT$(startTime, 2)) minute = VAL(MID$(startTime, 4, 2)) isPM = RIGHT$(startTime, 2) ' Check if the given time is in PM, and convert to 24-hour format IF isPM = "PM" AND hour <> 12 THEN hour = hour + 12 END IF ' Add the total minutes minute = minute + totalMinutes ' Adjust the hour and minutes accordingly hour = hour + (minute \ 60) minute = minute MOD 60 hour = hour MOD 24 ' Convert back to 12-hour format and set the correct AM/PM indicator IF hour >= 12 THEN IF hour > 12 THEN hour = hour - 12 isPM = "PM" ELSE IF hour = 0 THEN hour = 12 isPM = "AM" END IF ' Format the resulting time string and return it FUNCTION = FORMAT$(hour, "00") & ":" & FORMAT$(minute, "00") & " " & isPM END FUNCTION
Code:
FUNCTION PBMAIN () AS LONG DIM startTime AS STRING DIM totalMinutes AS LONG DIM endTime AS STRING startTime = "08:00 PM" totalMinutes = 90 endTime = AddMinutesToTime(startTime, totalMinutes) PRINT "Start Time: " & startTime PRINT "End Time: " & endTime END FUNCTION
Yes, I could have figured this out myself but I think it's a fine illustration on AI's usefulness in programming.
Comment