Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Go Program to Calculate Profit or Loss

by suresh

This go program uses the actual product cost and the sales amount to calculate profit or loss. It uses an else if statement to print output.

  • If the product cost is greater than the sales price, then loss.
  • If the sales price is higher than the product cost, then the product is profit—otherwise, no profit or loss.
package main

import "fmt"

func main() {

    var pcost, sa, amount int

    fmt.Print("\nEnter the Actual Product Cost = ")
    fmt.Scanln(&pcost)

    fmt.Print("\nEnter the Sale Price = ")
    fmt.Scanln(&sa)

    if sa > pcost {
        amount = sa - pcost
        fmt.Println("Total Profit = ", amount)
    } else if pcost > sa {
        amount = pcost - sa
        fmt.Println("Total Loss = ", amount)
    } else {
        fmt.Println("No Profit No Loss")
    }
}
Go Program to Calculate Profit or Loss 1

Golang Program to Calculate Profit or Loss

In this go program, we used an arithmetic operator to find the profit or loss.

package main

import "fmt"

func main() {

    var pcost, sa, amount int

    fmt.Print("\nEnter the Actual Product Cost = ")
    fmt.Scanln(&pcost)

    fmt.Print("\nEnter the Sale Price = ")
    fmt.Scanln(&sa)

    if sa-pcost > 0 {
        amount = sa - pcost
        fmt.Println("Total Profit = ", amount)
    } else if pcost-sa > 0 {
        amount = pcost - sa
        fmt.Println("Total Loss = ", amount)
    } else {
        fmt.Println("No Profit No Loss")
    }
}
Go Program to Calculate Profit or Loss 2

Placed Under: Go Examples

  • Golang Hello World Program
  • Go Add Two Number
  • Go Compound Interest
  • Go Count Digits in a Number
  • Go Cube of a Number
  • Go Even or Odd
  • Go Largest of Three Numbers
  • Go Reverse Natural Numbers
  • Go Multiplication Table
  • Go Number divisible by 5 and 11
  • Go Positive or Negative
  • Go Power of a Number
  • Go Print Natural Numbers
  • Go Profit or Loss
  • Go Print 1 to 100 without loop
  • Go Program to Print 1 to 100
  • Go Product of Digits in a Number
  • Go Palindrome Number Program
  • Go Print Even Numbers
  • Go Print Odd Numbers
  • Go Factors of a Number
  • Go Perfect Number
  • Go Prime Number
  • Go Reverse a Number
  • Go Simple Interest
  • Go Square of a Number
  • Go Square root of a Number
  • Go Sum of Digits in a Number
  • Go Sum & Avg of Natural Nums
  • Go Sum of Even Numbers
  • Go Sum of Odd Numbers
  • Go Sum of Even and Odd
  • Go Sphere Vol & Surface Area
  • Go Cylinder Vol & Surface Area
  • Go Cuboid Vol & Surface Area
  • Go Cube Volume & Surface Area
  • Go Cone Volume & Surface Area

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy