-
-
Notifications
You must be signed in to change notification settings - Fork 714
Add solution for Challenge 18 by Sairaviteja27 #610
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,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 | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // 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
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 TODO comments and consider simplifying the return. Similar to 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // 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 | ||||||||||||
| } | ||||||||||||
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 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:
Note: Using
9.0/5.0makes it explicit that floating-point division is intended, though9/5works correctly here due to type conversion.📝 Committable suggestion
🤖 Prompt for AI Agents