Question

Write a C program which creates a template for a structure to store somebody's date of...

Write a C program which creates a template for a structure to store somebody's date of birth (day, month, and year). Then write a C function that takes two such structure, one which represents the date of birth, and the other today's date, and returns the age of the user in years. Your function can either provide the full year only (integer) or the floating point age (bonus marks).

Next, write a C program which asks the user to enter their name and date of birth (day, month and year, and then stores this in the structure defined above. Your program should then determine the user's age by calling the function, then display to the screen whether the user is legally permitted to drink alcohol (18 years old or above).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

struct date{
int day;
int month;
int year;
};
int calculateAge(struct date a,struct date b){
return b.year-a.year;
}
int main()
{
char arr[100];
printf("Enter your name: ");
gets(arr);
struct date a,b;
printf("Enter day of birth: ");
scanf("%d",&a.day);
printf("Enter month of birth: ");
scanf("%d",&a.month);
printf("Enter year of birth: ");
scanf("%d",&a.year);
  
b.day=8;b.month=10;b.year=2019;
if(calculateAge(a,b)>=18){
printf("You are legally permitted to drink alcohol.")
}
else{
printf("You are not permitted to drink alcohol.");
}
return 0;
}

The output is

input Enter your name: Chris H Enter day of birth: 13 Enter month of birth: 1 Enter year of birth: 1998 You are legally permi

Add a comment
Know the answer?
Add Answer to:
Write a C program which creates a template for a structure to store somebody's date of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that determines the user's age after the   user enters both the current...

    Write a C++ program that determines the user's age after the   user enters both the current date and hisher birthdate as 3   integers:                yyyy mm dd                                                                                             Define a class which is named DateType and will be used to     declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy and it will have a second function named     “input”...

  • - Classes Write a C++ program that creates a class called Date that includes three pieces...

    - Classes Write a C++ program that creates a class called Date that includes three pieces of information as data members, namely:  month (type int)  day (type int)  year (type int). Program requirements: - Provide set and a get member functions for each data member. - For the set member functions assume that the values provided for the year and day are correct, but in the setMonth member function ensure that the month value is in the...

  • C++ Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class...

    C++ Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class implementation file) 200_assign4.cpp (application program) 200_assign4.pdf (sample runs) For your fourth programming assignment you will be writing the following C++ program: The formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years. Your target heart rate is a range that is 50-85% of your maximum heart rate. Create a class called HeartRates. The class attributes should...

  • in python Write a program that reads the date of birth from the user as 3...

    in python Write a program that reads the date of birth from the user as 3 integer values (day, month, year) and then computes and prints their exact age in days. You need to take into account the leap You may not use any built-in functions related to date and time! Example: Someone born on 01/01/2000 is 365 days * 18 years + 5 days (since the years 2000, 2004, 2008, 2012, and 2016 are all leap years) + 352...

  • Write a program called RentalRate.java which reads in a date of birth, today’s date and a...

    Write a program called RentalRate.java which reads in a date of birth, today’s date and a male/female designation from the user, and will then determine the basic daily and weekly rates for rental of an economy class car. Rental rate classes are: Best rate (male drivers, age 33–65 and female drivers, age 30-62)--$40.00per day, $200.00 per week Risk rate 1 (female drivers, age 25–29)–Best rate plus $10.00 per day or best rate plus $55.00 per week. Risk rate 2 (male...

  • Write program that prompts the user to enter a person's date of birth in numeric form...

    Write program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle...

  • 1. Write a Python program that will determine if the user can vote or not. The...

    1. Write a Python program that will determine if the user can vote or not. The program will ask the user to enter integer numbers that represent year, month, and day of birth. Also, the program will ask the user to enter the current year, current month, and current day. The program will determine if the user is allowed to vote or not. If the user age is greater than or equal 18 then the program will print the following...

  • Write a program that prompts the user to enter a person's birth date in numeric form...

    Write a program that prompts the user to enter a person's birth date in numeric form (e.g. 8-27-1980) and outputs the date of birth in the format of month day, year (e.g. August 27, 1980). Your program must work for three types of exceptions - invalid day, invalid month and invalid year (year must be between 1915 and 2015). Make these as class driven exceptions. Use one try-catch block with separate catches for the exception classes to handle errors for...

  • Write a C function named date() that receives an integer number of the long date, date...

    Write a C function named date() that receives an integer number of the long date, date form is yyyymmdd, such as 20070412; and the addresses of three variables named month, day, and year. determines the corresponding month, day, and year; and returns these three values to the calling function. For example, if date() is called using the statement     longdate=20200411; date(longdate, &month, &day, &year); the number 4 should be returned in month, the number 11 in day, and the number...

  • C Program Date Validation

    A date is composed of Day, Month and Year. Write A C Program that allows a user to input a Given Date (Month And Year from January 1900 up to 31st December 2100, and verify whether that date is Correct or Not.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT