Please create a program as follows: You need to calculate cost of a phone call t
ID: 3914335 • Letter: P
Question
Please create a program as follows: You need to calculate cost of a phone call to Colombia based on number of minutes the caller was on a phone. Rates are as follow: up to 5 min $1 a minute up to 10 min (but more than 5 min) $0.80 a minute up to 30 min (but more than 10 min) $0.50 a minute more than 30 minutes $0.25 a minute The program receives a number of minutes form the user, then calculates the amount to pay. The display should include: 1) number of minutes entered 2) the rate determined for the number of minutes 3) the amount of money in $$ that the call costs. Keep your program as simple as possible HINT: use IF statements to determine the rateExplanation / Answer
as the programming language is not speified i woul present the java,c++ implementation,
c++:
#include<iostream>
using namespace std;
int main()
{
double n;
cout<<"enter number of minutes"<<endl;
cin>>n;
double cost=0;double rate=0;
if(n>0 && n<=5)
{ rate=1;
cost=n*rate;
}
else if(n>5 && n<=10)
{rate=0.8;
cost=n*rate;}
else if(n>10 && n<=30)
{rate=0.5;
cost=n*rate;
}
else if(n>30)
{rate=0.25;
cost=n*rate;}
cout<<"number of minutes:"<<n<<" rate per minute: "<<rate<<" cost of call: "<<cost;
}
java:
import java.util.Scanner;
class call{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter number of minutes");
double n=sc.nextInt();
double cost=0;double rate=0;
if(n>0 & n<=5)
{ rate=1;
cost=n*rate;
}
else if(n>5 & n<=10)
{rate=0.8;
cost=n*rate;}
else if(n>10 & n<=30)
{rate=0.5;
cost=n*rate;
}
else if(n>30)
{rate=0.25;
cost=n*rate;}
System.out.println("number of minutes:"+n+" rate per minute: "+rate+" cost of call: "+cost);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.