Reputation: 31
I am attempting to write code that checks the validity of a date [day and month only], inputs that date [day and month] into a "Date" structure, and then, finally, checks that the code in fact did what I expected it to do in a test function, by printing "SUCCESS" if successful, or "FAILURE" if not;
I have tried everything, and cannot think of what the problem might be; I am getting no warnings, so debugger didnt help. the code compiles and runs, however, there is nothing being printed on screen to let me know if it is actually working or not;
Any feedback would be greatly appreciated, thank you!
#include <stdio.h>
#include <stdlib.h>
#include "PatientData.h"
#define INVALID -100
#define SUCCESS 0
int main()
{
int datechecker(int month, int day) {
int ret = SUCCESS;
month = 2;
day = 2;
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
|| month == 10 || month == 12)
{
if(!(day >= 1 && day <= 31))
ret = INVALID;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
if(!(day >= 1 && day < 31 ))
ret = INVALID;
}
else
{
ret = INVALID;
}
return(ret);
}
Date CreateDate(int day, int month)
{
Date date;
int ret = datechecker(2,2);
if (ret == SUCCESS)
{
date.Day = day;
date.Month = month;
}
else
{
date.Day = INVALID;
}
return date;
}
void CreateDateTest ()
{
Date date = CreateDate(2,2);
if (date.Day == 2)
{
printf("PASSED");
}
else
{
printf("FAILED");
}
}
return 0;
}
Upvotes: 1
Views: 211
Reputation: 1723
Well, you have three functions defined inside main
, called CreateDate
, CreateDateTest
, and datechecker
. However, the lone executable statement inside main
is return 0
, which is what your program is faithfully doing.
Your code cannot be run as such since PatientData.h
is not available, but I suspect it will work once you call CreateDateTest
from main
.
Upvotes: 2