Question

You will be developing a program that determines if a date is between a start and...

You will be developing a program that determines if a date is between a start and end date.

Ask the user for a starting and ending date in the form of YYYY MM DD.

Then ask the user for a date in the same form. If the date is between the starting and ending date, print "IN RANGE", otherwise print "OUT OF RANGE".

Example

Enter start date: 2017 1 24
Enter end date  : 2019 1 24
Enter date      : 2018 1 5
IN RANGE

Enter start date: 2017 1 24
Enter end date  : 2019 1 24
Enter date      : 1952 7 16
OUT OF RANGE
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Since you have not mentioned the language of your preference, I am providing the code in C++.

CODE

===============

#include <iostream>

using namespace std;

bool isDateInRange(int day, int month, int year, int startDay, int startMonth, int startYear, int endDay, int endMonth, int endYear){

int entryDate = (year * 10000) + (month * 100) + day;

int startDate = (startYear * 10000) + (startMonth * 100) + startDay;

int endDate = (endYear * 10000) + (endMonth * 100) + endDay;

if (entryDate >= startDate && entryDate <= endDate){

return true;

}

else{

return false;

}

}


int main() {

int startDay, startMonth, startYear, endDay, endMonth, endYear;

int day, month, year;

cout << "Enter start date: ";

cin >> startYear >> startMonth >> startDay;

cout << "Enter end date: ";

cin >> endYear >> endMonth >> endDay;

cout << "Enter date: ";

cin >> year >> month >> day;

if (isDateInRange(day, month, year, startDay, startMonth, startYear, endDay, endMonth, endYear) == 1) {

cout << "IN RANGE";

} else {

cout << "OUT OF RANGE";

}

}

Add a comment
Know the answer?
Add Answer to:
You will be developing a program that determines if a date is between a start and...
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
  • 3. Date Printer Write a program that reads string from the user containing a date in...

    3. Date Printer Write a program that reads string from the user containing a date in the form mm/dd/yyyy. It should print the date in the form March 12, 2014 . ( it is starting out with python third edition ) Can anyone please do it by python program .

  • IN PYTHON, Write a program that reads a string from the user containing a date in...

    IN PYTHON, Write a program that reads a string from the user containing a date in the form mm/dd/ yyyy. It should print the date in the form April 12, 2017. Hint: Get the "mm" from the user entered date "mm/dd/yyyy", then convert the "mm" into a month number. You may use an list month_list = ['January', 'February','March','April', 'May','June', 'July','August', 'September', 'October', 'November', 'December']. Use the month number you got from "mm" to get the month name.

  • Python 3. Date Printer Write a program that reads a string from the user containing a...

    Python 3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018 3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018

  • Write a program that accepts a date from the user in the form mm/dd/yyyy

    # C PROGRAMMING LANGUAGEWrite a program that accepts a date from the user in the form mm/dd/yyyy and then dis- plays it in the form month dd, yyyy, where month is the name of the month: Enter a date (mm/dd/yyyy): 2/17/2011 You entered the date February 17, 2011 Store the month names in an array that contains pointers to strings.

  • 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”...

  • The assignment : Assignment You will be developing a speeding ticket fee calculator. This program will...

    The assignment : Assignment You will be developing a speeding ticket fee calculator. This program will ask for a ticket file, which is produced by a central police database, and your program will output to a file. Furthermore, your program will restrict the output to the starting and ending dates given by the user. The ticket fee is calculated using four multipliers, depending on the type of road the ticket was issued: Interstate multiplier: 5.2252 Highway multiplier: 9.4412 Residential multiplier:...

  • Write a program that reads a string from the user containing a date in the form...

    Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018   I am asking for help in basic python please

  • can you please help with this problem? [L8-2] (date_parse.java) Complete the provided code, finishing the function...

    can you please help with this problem? [L8-2] (date_parse.java) Complete the provided code, finishing the function parse_date(dstring). When called, pass dstring as mm/dd/yyyy, where mm, dd, and yyyy are integers. The function should split dstring into individual strings, convert each to integer month, day, and year, then return the tuple (month,day,year). The provided main() reads date as a str value from the user, calls parse_date(date), then prints out the returned result. Note: the starting code is here: def parse_date(dstring): '''...

  • Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program...

    Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program should use a single input statement to accept the date, storing each piece of the date into an appropriate variable. Demonstrate that the input was obtained correctly by outputting the month, day, and year to the screen. Sample output: Enter (date (mm/dd/yyyy): 02/08/2011 Month entered: 2 Day entered: 8 Year entered: 2011 Challenge: Although the user entered 02, C++ drops the 0 as insignificant...

  • Write a java program Problem 4 involves a date in the form of mm/dd/yyyy. You must...

    Write a java program Problem 4 involves a date in the form of mm/dd/yyyy. You must write a java program that checks if a date is valid or not , make sure that the program tells you where the error is in the program if there is one . I want you to work with characters and the switch statement, and write out a reason for each incorrect input value. .

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