Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:10:43+00:00 2026-06-14T17:10:43+00:00

Hi I am new to Go programing language. I am learning from http://www.golang-book.com/ In

  • 0

Hi I am new to Go programing language.

I am learning from http://www.golang-book.com/

In chapter 4, under Exercises, there is a question on converting from Fahrenheit to Centigrade.

I coded up the answer as follows

    package main

import "fmt"

func main(){

    fmt.Println("Enter temperature in Farentheit ");

    var input float64

    fmt.Scanf("%f",&input)

    var outpu1 float64 = ( ( (input-32)* (5) ) /9)
    var outpu2 float64=  (input-32) * (5/9)
    var outpu3 float64= (input -32) * 5/9
    var outpu4 float64=  ( (input-32) * (5/9) ) 

    fmt.Println("the temperature in Centigrade is ",outpu1)
    fmt.Println("the temperature in Centigrade is ",outpu2)
    fmt.Println("the temperature in Centigrade is ",outpu3)
    fmt.Println("the temperature in Centigrade is ",outpu4) 
}

The output was as follows

sreeprasad:projectsInGo sreeprasad$ go run convertFarentheitToCentigrade.go 
Enter temperature in Farentheit 
12.234234
the temperature in Centigrade is  -10.980981111111111
the temperature in Centigrade is  -0
the temperature in Centigrade is  -10.980981111111111
the temperature in Centigrade is  -0

My question is with outpu2 and outpu4. The parenthesizes are correct but how or why does it print -0.

Could anyone please explain

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:10:44+00:00Added an answer on June 14, 2026 at 5:10 pm

    Quite simply, the expression (5/9) is evaluated as (int(5)/int(9)) which equals 0. Try (5./9)

    And to clarify why this is happening, it deals with the order in which the expression variable’s types are determined.

    I would guess that b/c (5/9) exists without regards to input in case 2 and 4 above, the compiler interprets them as int and simply replaces the expression with 0, at which point then the zero is considered dependent on input and thus takes on the type float64 before final compilation.

    Generally speaking, Go does not convert numeric types for you, so this is the only explanation that would make sense to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand it is kind of bloated question, but.... learning new language, you first
I am new to programming and am learning Python as my first language. I
i got a new programing book (multicore programming by cameron hughes, tracey hughes). so
I am new to the programming language IDL (Interactive Data Language) and am learning
Does anyone have a standard project that they use when learning a new language.
I've been learning Haskell for some time now and with every new programming language
I'm learning Ruby. I've got the O'Reilly book, The Ruby Programming Language, which states
Without learning new programing languages, can we using Java get .exe (executable windows file)
What features could be added to a new programming language to make it more
What is the real benefit of creating a new programming language? It is highly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.