cpp to go: convert degreesC to degreesF



From C++
#include 
using namespace std;

int main()
{
    //enter the temp in C
    int celsius;
    cout << "Enter the temperature in Celsius: ";
    cin >> celsius;

    //convert C into F values
    int fahrenheit;
    fahrenheit = celsius * 9/5 + 32;

    //output the results(followed by a new line)
    cout << "Fahrenheit value is: ";
    cout << fahrenheit << endl;

    return 0;
}
...to golang:
package main
import "fmt"

func main() {
    var celsius float64
    fmt.Printf("Enter the temperature in Celsius: ")
    fmt.Scanf("%g", &celsius)

    var fahrenheit float64
    fahrenheit = celsius * 9/5 + 32
    fmt.Printf("Fahrenheit value is: %g\n", fahrenheit)
}

No comments:

Post a Comment