Question

Write a C/C++ program that determines exactly how
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int year;
char month;
int hours;
cout << "Please hours: ";
cin >> hours;
cout << "Please year: ";
cin >> year;
cout << "Please month: ";
cin >> month;
cin >> day;
cout << "Please day: ";
if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
        {
            leap=1;
            }
            else
            leap=2;

if( month='jan' || 'March' || 'May' || 'July' || 'August' || 'October' || 'December' )
   {
    numberofdays=31;
}
  
   if( month='April' || 'June' || 'September' || 'November' )
   {
    numberofdays=30;
}
  
if( month='feb' && leap=1)
   {
numberofdays=28;
}
if( month='feb' && leap=2)
   {
numberofdays=28;
}
//creating an array
previous date={hours,year,month,day};

// generating for current date
tm *ltm = localtime(&now);

   // print various components of tm structure.
   cout << "Year" << 1900 + ltm->tm_year<<endl;
   cout << "Month: "<< 1 + ltm->tm_mon<< endl;
   cout << "Day: "<< ltm->tm_mday << endl;
   cout << "Time: "<< 1 + ltm->tm_hour << ":";
   cout << 1 + ltm->tm_min << ":";
   cout << 1 + ltm->tm_sec << endl;
present date={1 + ltm->tm_hour,1900 + ltm->tm_year,1 + ltm->tm_mon,1 + ltm->tm_hour};
double difference = std::difftime(present date, previous date) / (60 * 60 * 24);
std::cout << "difference = " << difference << " days" << std::endl;
}

output:

Please hours:9

Please year:1776

Please month:7

Please day:4

difference = 87838 days

//

Please hours:2

Please year:1492

Please month:10

Please day:12

difference = 191406 days
Add a comment
Know the answer?
Add Answer to:
Write a C/C++ program that determines exactly how many hours have passed since a previous historical...
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”...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • In C++ array. It should use an int numEvents' to keep track of how many events have been entered in the array. An event should be represented by a struct with several member variables. An event S...

    In C++ array. It should use an int numEvents' to keep track of how many events have been entered in the array. An event should be represented by a struct with several member variables. An event Strings for a name, description, and notes A date and time represented by their own structs. The Date struct should contain an int day, string month, and int year, and the Time struct should contain an int hour, int minute, int second, and bool...

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:      ...

  • CASE 20 Enron: Not Accounting for the Future* INTRODUCTION Once upon a time, there was a...

    CASE 20 Enron: Not Accounting for the Future* INTRODUCTION Once upon a time, there was a gleaming office tower in Houston, Texas. In front of that gleaming tower was a giant "E" slowly revolving, flashing in the hot Texas sun. But in 2001, the Enron Corporation, which once ranked among the top Fortune 500 companies, would collapse under a mountain of debt that had been concealed through a complex scheme of off-balance-sheet partnerships. Forced to declare bankruptcy, the energy firm...

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