Advertisement
karlakmkj

do..while Loop for temp conversion

Jan 13th, 2021
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.42 KB | None | 0 0
  1. fun main() {
  2.   var index = 0
  3.   val celsiusTemps = listOf(0.0, 87.0, 16.0, 33.0, 100.0, 65.0)
  4.   val fahr_ratio = 1.8
  5.   var fahr: Double
  6.  
  7.   println("-- Celsius to Fahrenheit --")
  8.   // Write your code below
  9.   do {
  10.     fahr = celsiusTemps[index] * fahr_ratio + 32.0
  11.   println("${celsiusTemps[index]}C = ${fahr}F")
  12.   index++
  13.   } while (fahr != 212.0) //once fahr value in the list calculated reaches 212, will exit loop
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement