-
-
Notifications
You must be signed in to change notification settings - Fork 713
Add solution for Challenge 18 by AlexO-85 #691
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||
| 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 | ||||||||||||
| return Round(celsius*9.0/5.0 + 32.0, 2) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // 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 | ||||||||||||
|
Comment on lines
+30
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove leftover TODO comments. The function is already implemented correctly, so these TODO comments from the template should be removed. Apply this diff: - // TODO: Implement this function
- // Remember to round to 2 decimal places
return Round((fahrenheit - 32.0) * 5.0 / 9.0, 2)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| return Round((fahrenheit - 32.0) * 5.0 / 9.0, 2) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Round rounds a float64 value to the specified number of decimal places | ||||||||||||
| func Round(value float64, decimals int) float64 { | ||||||||||||
|
Comment on lines
+35
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add documentation comment for exported function. Go best practices require documentation comments for all exported identifiers. The Round function needs a documentation comment explaining its purpose and parameters. Apply this diff: -// Round rounds a float64 value to the specified number of decimal places
+// Round rounds a float64 value to the specified number of decimal places.
+// For example, Round(3.14159, 2) returns 3.14.
func Round(value float64, decimals int) float64 {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| precision := math.Pow10(decimals) | ||||||||||||
| return math.Round(value*precision) / precision | ||||||||||||
| } | ||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove leftover TODO comments.
The function is already implemented correctly, so these TODO comments from the template should be removed.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents