My name is Doug and I'm new to the forums. I am currently taking a C programming class and it's the only language I have studied besides visual basic. I am having a lot of trouble with with the current project I have been assigned and received very little help from the teaher. I was wondering if I could find some help in here! Anyway I will state the problem and what I have and be open to any suggestions. Thank you so much and i hope someone can help!
The programming supervisor was pleased with the solution to Program 2. The supervisor would now like you to update your solution to Program 2 to develop a more robust Phone-call Cost Calculating System. Modify your solution as follows, in order to divide the program into functions, validate the input and allow the user to enter data on any number of calls. This program will include functions, loops and validation.
1. Write functions to do the following:
1. getStartTime()
to input the start time from the user. If the input value is not valid, continue to request a valid start time from the user and return the valid value to main().
2. getLengthofCall()
to input the length of the call from the user. If the input value is not valid, continue to request a valid length of time from the user and return the valid value to main().
3. calcGross()
to receive the start time and length of the call. The function should calculate the gross cost and return the value to main().
4. calcNet()
to receive the gross cost, the start time and the length of the call. The function should calculate the net cost by applying the discounts add tax as appropriate and return the net cost to main().
5. displayReport()
to receive the gross cost and net cost. The function is to display the output report for the user. The function returns no value to main().
2. Allow the user to continue entering data on calls until the user enters a sentinel for end of file. The programmer may determine the sentinel but must inform the user about how to terminate the program.
3. At the end of the program, display a thank you message to the user for using the phone call calculator program.
This is what I got for the same problem without the loop and functions it works perfectly! However I am not sure how to switch it into functions and apply the loop. Please help!
Below is my code that must meet the new standards listed above.
Code:
//Doug Miller
//Project #2 - Phone Bill Calculation Program
#include <stdio.h>
#include <conio.h>
int main()
{
// Declare Variables
int start_Time = 0;
int length_Of_Call = 0;
double gross_Cost = 0;
double net_Cost = 0;
double pre_Tax = 0;
double time_Discount = 0;
double minutes_Discount = 0;
//Gather Information
printf("Please enter your call starting time (world clock): ");
scanf("%d", &start_Time);
printf("Please enter length of call: ");
scanf("%d", &length_Of_Call);
if( start_Time > 1800 || start_Time < 800)
{
if (length_Of_Call > 60)
{ gross_Cost = (float)(length_Of_Call * .10);
pre_Tax = (gross_Cost - (gross_Cost * .50));
minutes_Discount = (pre_Tax - (pre_Tax * .15));
net_Cost = (float)(minutes_Discount + (minutes_Discount * .04));
}
else
{
gross_Cost = (float)(length_Of_Call * .10);
pre_Tax = (gross_Cost - (gross_Cost * .50));
net_Cost = (float)(pre_Tax + (pre_Tax * .04));
}
}
else if (length_Of_Call > 60)
{
gross_Cost = (float)(length_Of_Call * .10);
minutes_Discount = (gross_Cost - (gross_Cost * .15));
net_Cost = (float)(minutes_Discount + (minutes_Discount * .04));
}
else
{
gross_Cost = (float)(.10 * length_Of_Call);
net_Cost = (float)(gross_Cost + (gross_Cost * .04));
}
printf("\n\nStart Time: %d", start_Time,"\n\n");
printf("\n\nLength of call: %d", length_Of_Call,"\n\n");
printf("\n\nGross Cost: %.2f", gross_Cost,"\n\n");
printf("\n\nNet Cost: %.2f", net_Cost,"\n\n");
getch();
return 0;
}