Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions challenge-18/submissions/Sairaviteja27/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"math"
)

func main() {
// Example usage
celsius := 25.0
fahrenheit := CelsiusToFahrenheit(celsius)
fmt.Printf("%.2f°C is equal to %.2f°F\n", celsius, fahrenheit)

fahrenheit = 68.0
celsius = FahrenheitToCelsius(fahrenheit)
fmt.Printf("%.2f°F is equal to %.2f°C\n", fahrenheit, celsius)
}

// CelsiusToFahrenheit converts a temperature from Celsius to Fahrenheit
// Formula: F = C × 9/5 + 32
func CelsiusToFahrenheit(celsius float64) float64 {
// TODO: Implement this function
// Remember to round to 2 decimal places
fah := Round(celsius * 9/5 + 32, 2)
return fah
Comment on lines +22 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove TODO comments and consider simplifying the return.

The function is already implemented, so the TODO comments should be removed. Additionally, the intermediate variable can be eliminated for cleaner code.

Apply this diff to remove TODOs and simplify:

-	// TODO: Implement this function
-	// Remember to round to 2 decimal places
-	fah := Round(celsius * 9/5 + 32, 2)
-	return fah
+	return Round(celsius*9.0/5.0+32, 2)

Note: Using 9.0/5.0 makes it explicit that floating-point division is intended, though 9/5 works correctly here due to type conversion.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: Implement this function
// Remember to round to 2 decimal places
fah := Round(celsius * 9/5 + 32, 2)
return fah
return Round(celsius*9.0/5.0+32, 2)
🤖 Prompt for AI Agents
In challenge-18/submissions/Sairaviteja27/solution-template.go around lines 22
to 25, remove the leftover TODO comments and simplify the function by returning
the rounded Fahrenheit directly instead of assigning to an intermediate
variable; replace the two-line implementation with a single return of
Round(celsius*9.0/5.0+32, 2) (using 9.0/5.0 to make floating-point division
explicit).

}

// FahrenheitToCelsius converts a temperature from Fahrenheit to Celsius
// Formula: C = (F - 32) × 5/9
func FahrenheitToCelsius(fahrenheit float64) float64 {
// TODO: Implement this function
// Remember to round to 2 decimal places
cel := Round((fahrenheit - 32) * 5/9, 2)
return cel
Comment on lines +31 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove TODO comments and consider simplifying the return.

Similar to CelsiusToFahrenheit, the TODO comments should be removed and the code can be simplified.

Apply this diff:

-	// TODO: Implement this function
-	// Remember to round to 2 decimal places
-	cel := Round((fahrenheit - 32) * 5/9, 2)
-	return cel
+	return Round((fahrenheit-32)*5.0/9.0, 2)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TODO: Implement this function
// Remember to round to 2 decimal places
cel := Round((fahrenheit - 32) * 5/9, 2)
return cel
return Round((fahrenheit-32)*5.0/9.0, 2)
🤖 Prompt for AI Agents
In challenge-18/submissions/Sairaviteja27/solution-template.go around lines 31
to 34, remove the TODO comment and simplify the function by returning the
rounded value directly; replace the temporary variable assignment with a single
return that calls Round((fahrenheit - 32) * 5.0/9.0, 2) (ensure float literals
for division) and remove any leftover TODO text.

}

// Round rounds a float64 value to the specified number of decimal places
func Round(value float64, decimals int) float64 {
precision := math.Pow10(decimals)
return math.Round(value*precision) / precision
}
Loading