Kotlin wrong answer

Viewed 50

i have a test about description : our friends really liked your program! Now they want to expand their theater and add screen rooms with more seats. However, this is expensive, so they want to make sure this will pay off. Help them calculate the profit from all the sold tickets depending on the number of available seats.

Objectives : In this stage, you need to read two positive integer numbers from the input: the number of rows and the number of seats in each row. The ticket price is determined by the following rules:

If the total number of seats in the screen room is not more than 60, then the price of each ticket is 10 dollars. In a larger room, the tickets are 10 dollars for the front half of the rows and 8 dollars for the back half. Please note that the number of rows can be odd, for example, 9 rows. In this case, the first half is the first 4 rows, and the second half is the rest 5 rows. Calculate the profit from the sold tickets depending on the number of seats and print the result as shown in the examples below. After that, your program should stop. Note that in this project, the number of rows and seats won't be greater than 9.

i code this but it gives me that the result is false ; what is the problem

fun main() {
    println("Enter the number of rows:")
    val rows = readln().toInt()
    println("Enter the number of seats in each row:")
    val seats = readln().toInt()
    val people = rows * seats                    //define the total seats 
    val price1 = 10
    val price2 = 8
    val front = rows / 2                   // the front rows 
    val people1 = front * seats           // people in the front part 
    val back = rows - front               // the back rows
    val people2 = back * seats            //people in the back part   
    val total1 = people * price1            // price in the 1st case 
    val total2 = people1 * price1 + people2 * price2    // price in second case 
    if (rows <= 9){
        if (people > 60) println("Total income:$total1") 
        
         
        else println( "Total income: $total2") 
    
    
      } 
   
    
}
1 Answers

In the description of the test it says

If the total number of seats in the screen room is not more than 60, then the price of each ticket is 10 dollars.

In your code that is people * price1 which is the value of total1.

So you should definitely check if you output total1 when there are not more than 60 people.

Also, is the format of your output important? Because in one case your result is preceded by Total income: and in the other case it is preceded by Total income: .

Related