Skip to content

Commit 5fe9204

Browse files
committed
calculated total prices using imperative style
1 parent 7db62c3 commit 5fe9204

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/scala/Prices.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
/*
3+
find the total of prices greater than $20, discounted by 10%.
4+
*/
5+
object Prices extends App{
6+
7+
val prices = List(10,12,15,25,20,18,30,21,48)
8+
9+
var totalDiscountPrices = 0.0
10+
11+
for(p <- prices){
12+
if(p > 20){
13+
totalDiscountPrices = totalDiscountPrices + p * 0.9
14+
}
15+
}
16+
17+
println(s"total of discounted prices $totalDiscountPrices")
18+
19+
}

0 commit comments

Comments
 (0)