Requesting help with the code

118 views
Skip to first unread message

Kareem Shaikh

unread,
Jan 27, 2020, 10:54:45 AM1/27/20
to golang-nuts
Hi All,

Good Afternoon.

My name is Kareem. 

I recently started learning GO on my own.

I am going through the book "INTRODUCTION TO GO" from RIELY.

I wrote a program to convert Degrees to Fahrenheit. It is as follows:

package main
import "fmt"

func main () {

  fmt.Println("Enter the degrees to convert into farenhiet: ")
  var Degrees float64
  fmt.Scanf("%f", &Degrees)
  var farenhiet float64
  farenhiet = ((Degrees*9)/5) + 32
  fmt.Println("&Degrees Degrees to Farenhiet is = ", Degrees, farenhiet)

}


In th last statement " fmt.Println("&Degrees Degrees to Farenhiet is = ", Degrees, farenhiet)" I wanted to print the value of the degrees and then the result.

I am struggling with this. 


Can anyone please tell me what should I change in order to get the right output?

For example:

I want to change 10 degrees to Fahrenheit.
I want to print "10 degrees to Fahrenheit is = 50"

Please help me with the code to print the exact line that I want.
I understand I can write the same statement as above but what I want exactly is that we never know what number(degrees) we input.
So please help me modify the code as per my requirement.

PS: Please help me with any books to read after the above mentioned book. 


Thank You. 

Sam Whited

unread,
Jan 27, 2020, 11:16:12 AM1/27/20
to golan...@googlegroups.com
On Mon, Jan 27, 2020, at 02:41, Kareem Shaikh wrote:
> Can anyone please tell me what should I change in order to get the right output?
>
> For example:
>
> I want to change 10 degrees to Fahrenheit.
> I want to print "10 degrees to Fahrenheit is = 50"

You want to use one of the formatting functions, for example:

fmt.Printf("%f Degrees to Fahrenheit is = %f\n", Degrees, fahrenheit)

For more information, see the fmt documentation: https://godoc.org/fmt

—Sam

--
Sam Whited

Jake Montgomery

unread,
Jan 27, 2020, 11:56:31 AM1/27/20
to golang-nuts
That's how I would do it. But you can also use fmt.Println, just change the order:
fmt.Println(Degrees, "to Farenhiet is =", farenhiet)
https://play.golang.org/p/XyQ7CtuWdbg

peterGo

unread,
Jan 27, 2020, 1:36:17 PM1/27/20
to golang-nuts
Kareem,

Here is an example,

package main

import "fmt"

func main() {
    fmt.Println("Enter degrees Celsius (℃): ")
    var celsius float64
    fmt.Scanf("%f", &celsius)
    var fahrenheit float64
    fahrenheit = ((celsius * 9) / 5) + 32
    fmt.Printf("%.2f℃ is %.2f℉\n", celsius, fahrenheit)
}


Output:

Enter degrees Celsius (℃):
10
10.00℃ is 50.00℉



Peter

Kareem Shaikh

unread,
Feb 17, 2020, 12:54:06 PM2/17/20
to golang-nuts
Thank You Peter.
I will try this.
Could you please let me know which are the subsequent books to follow for learning GO after "Introducing GO"?

Kareem Shaikh

unread,
Feb 17, 2020, 12:55:33 PM2/17/20
to golang-nuts
Hi Jake,

This works.
Thank You very much.

Could you please let me know which books should I follow to learn GO after completing "Introducing GO"?

Kareem Shaikh

unread,
Feb 17, 2020, 12:56:18 PM2/17/20
to golang-nuts
Hi Sam,


Thank You very much.
I will try this.

Could you please let me know which books should I follow to learn GO after completing "Introducing GO"?

Bob Strecansky

unread,
Feb 17, 2020, 9:26:01 PM2/17/20
to Kareem Shaikh, golang-nuts
If you haven't gone through "A tour of Go", I'd suggest it - it is pretty practical and helpful in learning the language:


"Go by Example" has a bunch of good resources too for practical use:


Hope this helps!

Bob

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/83fc2dbd-d3d0-4c55-b44f-66d27e121ab3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages