By Chernobyl
Here is another of my coding exercises from college, this will allow the operator to input a persons name, then it will ask for each call length in minutes until the bill is more than or equal to $100. It will then display the total number of calls, the total bill cost and the average cost per call
Code:
/*
Problem 2
By Stephen V (Chernobyl)
WwW.Console-World.Org
*/
#include <stdio.h>
void main()
{
char name[15];
short int callMins = 0, calls = 0, callNum = 1;
float callCost = 0, bill = 0, avCost = 0;
printf("Please enter the phone account holders name: ");
gets(name);
do
{
printf("Please enter the length (in minutes) of call %d:", callNum);
scanf("%d", &callMins);
if(callMins <= 5)
{
callCost = callMins * .15;
}
else
{
if(callMins <= 15)
{
callCost = (callMins - 5) * .10 + .75;
}
else
{
callCost = (callMins - 15) * .075 + 1.75;
}
}
bill = bill + callCost;
avCost = bill / callNum;
calls++;
callNum++;
}
while(bill <= 100);
//Display bill information
printf("\nTotal Calls: %d\n", calls);
printf("Bill total: $%.3f\n", bill);
printf("Average Call Cost: $%.3f", avCost);
printf("\n\nPress ENTER to continue!");
fflush(stdin);
getchar();
}