Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble with the output of this code, it is written in Kotlin. Every time I try to use it sends the error

I am having trouble with the output of this code, it is written in Kotlin. Every time I try to use it sends the error A 'return' expression required in a function with a block body ('{...}'). I am not sure what this means.

Here is the code (it takes in input from the user, the angle, and determines its positon)

fun compassDirection(angle: Double): Int { if(337.5<=angle && angle<=360) { return 1 } else if(292.5360) { return 9 } }

fun main(args : Array){ var angle : Double = args[0].toDouble() if(compassDirection(angle) == 1) { println("North West Direction") } else if(compassDirection(angle) == 2) { println("West Direction") } else if(compassDirection(angle) == 3) { println("South West Direction") } else if(compassDirection(angle) == 4) { println("South Direction") } else if(compassDirection(angle) == 5) { println("South East Direction") } else if(compassDirection(angle) == 6) { println("East Direction") } else if(compassDirection(angle) == 7) { println("North East Direction") } else if(compassDirection(angle) == 8) { println("North Direction") } else if(compassDirection(angle) == 9) { println("Invalid input. Value should be between 0 to 360 degree") } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions