My program's purpose is to add two time intervals (starting time and duration, respectively...these are the input values the user must enter) and display the result.
According to my professor, the error is in the GetEnding function. endingtime=startingtime+durationtime-60+100 is not a proper expression. It is true, because even 2505 (the time is supposed to be measured in military hours) is displayed as output, when it should read 0105 instead!
What can I do to fix this problem?
Code:
/*Project #34
Herbert Ortiz
Due: September 27, 2004
This programs adds two time intervals and displays the result*/
#include <stdio.h>
#include <conio.h>
#include <time.h>
typedef enum Bool {false=0, true} bool; //enable boolean functions
int GetStarting(int startingtime); //starting time function prototype
int GetDuration(int durationtime); //duration time function prototype
bool IsTimeValid(int startingtime); //validate starting time
bool IsDTimeValid(int durationtime); //validate duration time
int GetEnding(int startingtime, int durationtime, int endingtime); //obtain the output
main()
{
int startingtime, durationtime, endingtime; //local variable declaration
startingtime=GetStarting(startingtime); //function call for startingtime input
durationtime=GetDuration(durationtime); //function call for durationtime input
if(IsTimeValid(startingtime)&&IsDTimeValid(durationtime)) //the below will be executed if...
{
endingtime=GetEnding(startingtime, durationtime, endingtime); //then this will be carried out
}
getch();
}
int GetStarting(int startingtime) //function header/definition for starting time
{
printf("Please enter the time (military time): "); //input prompt 1
scanf("%d", &startingtime); //variable evaluated and stored in memory
return startingtime; //value will return to main() for display
}
int GetDuration(int durationtime) //function header/definition for duration time
{
printf("Please enter the duration: "); //input prompt 2
scanf("%d", &durationtime); //variable evaluated and stored in memory
return durationtime; //durationtime value will returns to main() for display
}
bool IsTimeValid(int startingtime) //validation function for starting time
{
if(startingtime<2400) //the condition for which the time is acceptable
{
return true;
}
else
{
return false; //otherwise, the input is not acceptable
}
}
bool IsDTimeValid(int durationtime) //validation function for duration time
{
if(durationtime<2400) //condition for which the time is acceptable
{
return true;
}
else
{
return false; //if not, the input is invalid
}
}
int GetEnding(int startingtime, int durationtime, int endingtime) //the end time function
{
endingtime=startingtime+durationtime-60+100; //the mathematical procedure
printf("Start time is %d. Duration is %d. End time is %d", startingtime, durationtime, endingtime);
scanf("%d", &endingtime); //output and its evaluation
getch();
}
Thanks a lot for your time!