Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
write a golang code for the problem:
Suppliers 'A' and 'B' provided the following numbers of products for the luxury hamper market:

>Product 'A' 'B' Price Per Unit

BelugaCaviar 5248 640 128

ChristmasCake 1312 1888 135

GammonJoint 2624 3776 234

VintagePort 5760 3776 156
ChampagneTruffles 3936 5664 250

Although the suppliers try very hard to ship their goods in perfect condition, there is inevitably some spoilage of 5% for each product - i.e. products gone bad.

Calculate:

The total amount which needs to be paid to supplier A and supplier B against each product

What I have tried:

package main

import (
"fmt"
)

func total(mymap map[string]float64) {
for k, _ := range mymap {
if k == "A" {
result := mymap["A"] - (mymap["A"] * 0.05)
total := result * mymap["unit_price"]
fmt.Printf("Total price for suplier A:%f\n", total)

} else if k == "B" {
result1 := mymap["B"] - (mymap["B"] * 0.05)
total1 := result1 * mymap["unit_price"]
fmt.Printf("Total price for suplier B:%f", total1)
}
fmt.Println()
}

}

func main() {

BelugaCaviar := map[string]float64{"A": 5248, "B": 640, "unit_price": 128}
ChristmasCake := map[string]float64{"A": 1312, "B": 1888, "unit_price": 135}
GammonJoint := map[string]float64{"A": 2624, "B": 376, "unit_price": 234}
vintagePort := map[string]float64{"A": 5760, "B": 3776, "unit_price": 156}
ChampagneTruffles := map[string]float64{"A": 3936, "B": 5664, "unit_price": 25}
fmt.Println("Price details for product BelugaCaviar are:")
total(BelugaCaviar)
fmt.Println("Price details for product ChristmasCake are:")
total(ChristmasCake)
fmt.Println("Price details for product GammonJoint are:")
total(GammonJoint)
fmt.Println("Price details for product vintagePort are:")
total(vintagePort)
fmt.Println("Price details for product ChampagneTruffles are:")
total(ChampagneTruffles)

}
Posted
Updated 23-Oct-22 1:00am
v3
Comments
Richard MacCutchan 23-Oct-22 3:41am    
The answer is the number of items multiplied by 0.95 (i.e. 5% less) multiplied by the price.

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900