Write a program that asks the user to enter a number of minutes and a number of seconds, then calculates and displays the cost of a telephone call according to the following rules:

  • a unit is equal to 20 seconds;
  • the first minute is indivisible and is equal to 3 units.

A unit is billed at 1.40 \$ for the the first 3 minutes and 1.20 \$ for the remaining minutes.

Useful hints !!
The number of minutes and seconds shouldn't be negative and shouldn't exceed sixty. 
Calculate first the total number of units, making sure to take into account the different possibilities, and then calculate the total cost based on the total number of units.


Running examples


Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
int main()
{
	int minutes, seconds, units, totalseconds;
	double total;
 
	do {
		printf("Enter the number of minutes: ");
		scanf("%d", &minutes);
	} while (minutes < 0 || minutes >60);

	do {
		printf("Enter the number of seconds: ");
		scanf("%d", &seconds);
	} while (seconds < 0 || seconds >60);

	if (minutes == 0)
		units = 3;
	else
	{ 
		totalseconds = minutes * 60 + seconds;
		units = totalseconds / 20;
		if (totalseconds % 20)
			units++;
	}

	if (units >= 9)
		total = 9 * 1.4 + (units - 9)*1.2;
	else
		total = units*1.4;

	printf("Cost of the call = %.2lf $\n", total);

	return 0;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
File names