Help with calculation and loop
Hi - I'm haveing problems with the calculation and loop. Here are my problems:
Calculation - When I enter in a start time and a length time the calculation is not coming out correctly and I can't seem to figure out why.
Loop - I had to write a line to say that you may enter another set by hitting the n key. I cannot figure out how to make it so that it automatically goes to the next set without hitting the n key.
Any help is greatly appreciated. Here is what I have coded so far.
Code:
#include <stdio.h>
#include <conio.h>
#define rate .10
#define discounta .50
#define discountb .15
#define tax .04
void getStartTime(int time);
void getLengthofCall(int length);
void calcGross(int time, int length, double gross);
void calcNet(int time, int length,double gross, double net);
void displayReport(double gross, double net, char input);
void end();
int main()
{
int time;
int length;
double gross;
double net;
char input;
getStartTime(time);
getLengthofCall(length);
calcGross(time, length, gross);
calcNet(time, length, gross, net);
displayReport(gross, net, input);
return 0;
}
void getStartTime(int time)
{
printf("Please input start time: ");
scanf("%d", &time);
if(time >= 2401 || time <= -1)
{
printf("Invalid time. Please input a time between 0 and 2400.\n\n");
main();
}
}
void getLengthofCall(int length)
{
printf("Please input call length: ");
scanf("%d", &length);
}
void calcGross(int time, int length, double gross)
{
if(time <= 800 || time >= 1800 && time <= 60)
{
gross = length*rate*discounta;
}
else if(time <= 800 || time >= 1800 && time >= 60)
{
gross = length*rate*discounta*discountb;
}
else
{
gross = length*rate;
}
}
void calcNet(int time, int length, double gross, double net)
{
if(time <= 800 || time >= 1800 && time <= 60)
{
net = gross*tax+gross;
}
else if(time <= 800 || time >= 1800 && time >= 60)
{
net = gross*tax+gross;
}
else
{
net = gross*tax+gross;
}
}
void displayReport(double gross, double net, char input)
{
printf("\nGross: %lf\nNet: %lf", gross, net);
printf("\nYou may enter another set by hitting the n key.\n");
printf("\nYou may exit this program by hitting the e key.\n");
scanf("%s", &input);
if (input!='e')
{
main();
}
else if(input='e')
{
end();
}
}
void end()
{
printf("\n\nThank you for using this phone calculator program!\n");
}
This is my output
[code
Please input start time: 1600
Please input call length: 15
Gross: -92559631349317831000000000000000000000000000000000 000000000000.000000
Net: -92559631349317831000000000000000000000000000000000 000000000000.000000
You may enter another set by hitting the n key.
You may exit this program by hitting the e key.
[/code]