All pastes #774525 Raw Edit

perry753

public c v1 · immutable
·published 2007-11-15 09:33 UTC
rendered paste body
// Lab B// Perry Huang// 11/14/07/*LAB B - Are you "IN"???The New Telephone Company has the following rate structure for long-distancecalls:1) Any call started after 6:00 pm (1800 hours) but before 8:00 am (0800hours) is discounted 50%.2) Any call started after 8:00 am (0800 hours) but before 6:00 pm (1800hours) is charged the regular rate.3) All calls are subject to a 4% Federal Tax. (after discounts)4) The regular rate for a call is $0.40 per minute.5) Any call longer than 60 minutes receives a 15% discount (after anyother discount is subtracted and before tax is added).Write a program that reads (from the user) the start time for a call based on a twenty-fourhour clock and the length of the call. The gross cost (before any discounts or tax) shouldbe printed followed by the net cost (after any discounts and tax). Use functions!!! Theprogram should repeat as long as the user desires.*/#include <stdio.h>#define TAX 0.04#define RATE 0.4#define FLUSH while(getchar()!='\n')void prompt();int callstart();int calllength();float grosscost(int);float discount50(int);float discount15(int);float tax(float);void output(int, int, float, float);void repeatf();void main(){	int start, length;	float gross, net;	prompt();	start = callstart();	length = calllength();	gross = grosscost(length);	net = gross;	net *= discount50(start);	net *= discount15(length);	net += tax(net);	output(start, length, gross, net);	repeatf();}void prompt(){	puts("Hi. We are a new telephone company specializing in long-distance calling. Any call started 1800 to 0800 is discounted 50%. All others are charged regular rate. All calls longer than 60 minutes is discounted 15%. All calls subject to tax. Regular rate is $0.40 per minute.");}int callstart(){	int callstartvalue = 0;	puts("Please input the start of the call. Input must be based on a 24-hour clock.");	scanf("%d", &callstartvalue);	FLUSH;	while (callstartvalue < 0 || callstartvalue > 2400)	{		puts("You have inputted an invalid value. Please try again and remember this is on a 24-hour clock.");		scanf("%i", &callstartvalue);		FLUSH;	}	return callstartvalue;}int calllength(){	int calllengthvalue = 0;	puts("Please input the length of the call. Input must be in minutes.");	scanf("%d", &calllengthvalue);	FLUSH;	while (calllengthvalue < 0)	{		puts("You have inputted an invalid value. Please try again.");		scanf("%i", calllengthvalue);		FLUSH;	}	return calllengthvalue;}float grosscost(int length){	float fart = length;	fart *= 0.40;	return (fart);}float discount50(int start){	if(start > 1800 || start < 800)	{		return (0.5);	}	else	{		return 1;	}}float discount15(int length){	if(length > 60)	{		return (0.85);	}	else	{		return 1;	}}float tax(float net){	return (net * TAX);}void output(int ostart, int olength, float ogross, float onet){	puts("\nYOUR CALL OVERVIEW");	printf("\n%20s%20s%20s%20s", "Start Time", "Length", "Gross cost", "Net cost");	printf("\n%20i%20i%20.2f%20.2f", ostart, olength, ogross, onet);	puts("\nWould you like to repeat this program? Enter Y for yes or N for no.");}void repeatf(){	char getme;	getme = getchar();	if (getme == 'Y' || getme == 'y')	{		puts("\nRepeating...");		main();	}	else	{		puts("\nDone.");	}}