HELPP plz! program that prints the cost of a call.

Write a program that prompts the user to enter the number of minutes a telephone call lasted
for. The program finds and prints the cost of the call. Assume that part of a minute is counted as one minute and the cost is calculated based on the following:
The call connection cost 0.3 Dirhams.
The cost of one minute is 0.7 Dirhams if the call lasted for less than 10 minutes.
The cost of each additional minute is 1.2 if the call lasted for 10 minutes or more.

The output should look like:
(Enter the number of minutes: 57
your call costs 64.2 dirhams.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#include<iostream>
using namespace std;
int main()
{
    float cost;
    int mins;


    cout<<"Enter the number of minutes: ";
    cin>>mins;

    
    if (mins<=1 && mins<10)

    {
    
    cout<<"The call lasted for "<<mins<<", and the cost is "<<(0.7*mins)+0.3<<" dirhams";

    }

    else if (mins>=10)

    {
        cost = (1.2*mins)+0.3;
        cout<<"The call lasted for "<<mins<<" , and the cost is "<<cost<<" dirhams";

    }

 return 0;
}
 
Last edited on
closed account (SECMoG1T)
if (mins<=1 && mins<10)
this will always return false if mins >1 and <10 maybe you meant to use if(mins>0&&mins<10)

Also note that if at any time the minutes are more then ten the first 9 minutes should be considered indipendently, you'll also need to take care of this
. Assume that part of a minute is counted as one minute
such that if you've got 29.3 or 29.8.. minutes they all equate to 30 mins
Last edited on
You make "min" as int variable and you still multiplying it with 0.7 (Actually you hope to get answer in decimal) but it won't. make it float.
Last edited on
my professor is asking for 64.2 as an ouput (cost of call) when inputting 57 (number of minutes), but I keep getting 68.7 .. I don't know if my professor made a mistake regarding her output..?
I replaced (int mins) with (float mins) & used if(mins>0 && mins<10), that was helpful.. but I still didn't get the output she's asking for.
Cost begins at 0.
For connection, add 0.3 to the cost.
For each minute under 10, add 0.7 to the cost.
Starting at minute 10, add 1.2 to the cost for each minute.

For 57:
Cost = 0

Add 0.3 for connection: Cost = 0.3

Cost >= 10, add the cost for the first 9 minutes.
Cost = 0.3 + (9*0.7) = 0.3 + 6.3 = 6.6

Add cost for the remaining minutes (57 minutes - 9 minutes already accounted for).
Cost = 6.6 + ((57-9) * 1.2) = 6.6 + (48 * 1.2) = 6.6 + 57.6 = 64.2
Thank you so much!
In C Simple and Neat :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <conio.h>
int main()
{	
	float min,cost;
	printf("Enter Minutes: ");
	scanf("%f",&min);
	if(min<10)
	{
		cost = 0.3 + (min*0.7);
		printf("\nCall Cost: $%.2f",cost);
	}
	else
	{
		cost = 6.6 + ((min-9) * 1.2);
		printf("\nCall Cost: $%.2f",cost);
	}
	getch();
	return 0;
}
Last edited on
Topic archived. No new replies allowed.