Skip to main content

Section 9.5 if - else Statement Practice

You are staying at a youth hostel that has the funniest pricing policy:
In order to encourage people to arrive early they charge more, the later you arrive on your day of check-in. You can arrive at any time between noon and midnight on the day of check-in, but the later you arrive, the more expensive the night will be.

Activity 9.3.

Write a C-program that reads from the user the hour of arrival (between 0 - meaning noon - and 12 - meaning midnight) and that then outputs the price to pay for the night.
The cost for the night is a $10 base fee plus $5 for every hour you arrive past noon. So if you arrive at noon, the total cost is only $10, if you arrive at 1pm, the price goes up to $15, etc. Thankfully the total price is capped at $57, so even if you arrive at 11pm, the price will be $57.

Compile and run the code below in your own C environment.

#include <stdio.h>

int main(void) {
    int hour;
    int price;
    printf("Please enter your arrival time - number of hours past noon: ");    
    scanf("%d", &hour);

    /* Please add your code here */

    printf("Your price for today is $%d.\n", price);
    return(0);
}