Need a project done?

C++ Programming Developer

Search This Blog

Age and Sleeping time Calculator in C++

/*
A GUIDE TO PROGRAMING IN C++ BY TIM CORICA
Write a program that calculates the number of hours of your life that you have spent sleeping. Assume that you sleep 8 hours each night. To simplify the problem , assume that there are always 30 days in each month , and 65 days in each year. The program output should look like this:

Enter your birthdate(using numbers for months):
month:9
day:27
year:1984
Enter today's date (using numbers for months):
month:10
day:26
year:2002
you have been alive for 6599 days.
you have slept for 52792 hours.

*/




#include <iostream>
using namespace std;

int main()
{
cout << "Enter your birthdate(using numbers for months): " << endl;
cout << "Month: "; int m; cin >> m;
cout << "Day: "; int d; cin >> d;
cout << "Year: "; int y; cin >> y;

cout << "\nEnter today's date (using numbers for months): " << endl;
cout << "Month: "; int tm; cin >> tm; // tm => Today's month
cout << "Day: "; int td; cin >> td;
cout << "Year: "; int ty; cin >> ty;

unsigned long int days_from_dateOfBirth = (365*ty + tm*30 + td) - (365*y + m*30 + d);
cout << "You have been alive for " << days_from_dateOfBirth << " days." << endl;
cout << "You have slept for " << days_from_dateOfBirth * 8 << " hours." << endl;
return 0;
}


10 comments:

"Don't let anyone ever make you feel like you don't deserve what you want."