First of all, let me start off by stating I'm a C newbie. So, please don't flame.
I'm in the process of writing my first program and I've run into a road block and could use some assistance.
Basically, here's what the program is supposed to do:
1. Ask the user for their Date of Birth in the format: mm/dd/yyyy
2. Ask the user for the current date in the format: mm/dd/yyyy
3. Once this information has been obtained, the program will tell you if you are 18 years of age or older.
Before anyone asks.....yes, this is for a begining C class I'm taking at school. I've finished writing it and it seems to be working fine....with the exception of a few dates.
Here's the source:
/*Age checking problem solution in C*/
#include <stdio.h>
main()
{
int m1, d1, y1, m2, d2, y2, yd; /*Declaration of integer variables:
m1= month of DOB
d1= day of DOB
y1= year of DOB
m2= month of date
d2= day of date
y2= year of date
yd= year of date - year of DOB*/
printf("Please enter the month of the DOB in the format mm:\n"
scanf("%d", &m1);
printf("Please enter the day of the DOB in the format dd:\n"
scanf("%d", &d1);
printf("Please enter the year of the DOB in the format yyyy:\n"
scanf("%d", &y1);
printf("\n"
printf("Please enter the month of today's date in the format mm:\n"
scanf("%d", &m2);
printf("Please enter the day of today's date in the format dd:\n"
scanf("%d", &d2);
printf("Please enter the year of today's date in the format yyyy:\n"
scanf("%d", &y2);
printf("\n"
yd= y2 - y1;
if(yd > 18)
printf("You are 18 years old or older!\n"
else
if(m2 < m1)
printf("You are not 18 years old or older!\n" else
if(d1 > d2)
printf("You are not 18 years old or older!\n"
else
printf("You are 18 years old or older!\n"
return 0;
}
Like I said, I'm new to C so you'll have to forgive my language structure. Any help is much appreciated!
p.s. We can not use nested functions for this program since we havn't learned that yet. We can only use If/else statements.
I'm in the process of writing my first program and I've run into a road block and could use some assistance.
Basically, here's what the program is supposed to do:
1. Ask the user for their Date of Birth in the format: mm/dd/yyyy
2. Ask the user for the current date in the format: mm/dd/yyyy
3. Once this information has been obtained, the program will tell you if you are 18 years of age or older.
Before anyone asks.....yes, this is for a begining C class I'm taking at school. I've finished writing it and it seems to be working fine....with the exception of a few dates.
Here's the source:
/*Age checking problem solution in C*/
#include <stdio.h>
main()
{
int m1, d1, y1, m2, d2, y2, yd; /*Declaration of integer variables:
m1= month of DOB
d1= day of DOB
y1= year of DOB
m2= month of date
d2= day of date
y2= year of date
yd= year of date - year of DOB*/
printf("Please enter the month of the DOB in the format mm:\n"
scanf("%d", &m1);
printf("Please enter the day of the DOB in the format dd:\n"
scanf("%d", &d1);
printf("Please enter the year of the DOB in the format yyyy:\n"
scanf("%d", &y1);
printf("\n"
printf("Please enter the month of today's date in the format mm:\n"
scanf("%d", &m2);
printf("Please enter the day of today's date in the format dd:\n"
scanf("%d", &d2);
printf("Please enter the year of today's date in the format yyyy:\n"
scanf("%d", &y2);
printf("\n"
yd= y2 - y1;
if(yd > 18)
printf("You are 18 years old or older!\n"
else
if(m2 < m1)
printf("You are not 18 years old or older!\n" else
if(d1 > d2)
printf("You are not 18 years old or older!\n"
else
printf("You are 18 years old or older!\n"
return 0;
}
Like I said, I'm new to C so you'll have to forgive my language structure. Any help is much appreciated!
p.s. We can not use nested functions for this program since we havn't learned that yet. We can only use If/else statements.