1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void graphical_welcome();
void printInstructions();
void userInput(int m1, int d1, int y1, int m2, int d2, int y2);
int main()
{
// Using an array, I numbered each month to have certain amount of corresponding
// days. January = 31, February = 28, etc.
int days_in_months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int d1, d2;
int m1, m2;
int y1, y2;
int year_diff, day_diff;
int month_total;
int reg_years = 365;
// The block above defines all variables for the program
// Display the Welcome Message and program instructions
graphical_welcome();
printInstructions();
// Function to prompt the user for input
userInput(m1, d1, y1, m2, d2, y2);
cin.ignore();
system("pause");
return 0;
}
void graphical_welcome()
{
cout << "|----------------------------------------------|" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| Welcome to the Calendar |" << endl;
cout << "| Dates Calculator |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "|----------------------------------------------|" << endl;
cout << "\n";
}
void printInstructions()
{
cout << "When prompted, please enter the numeric value " << endl;
cout << "of the month, day, and year you wish to " << endl;
cout << "find the difference of." << endl;
cout << "\n";
}
void userInput(int m1, int d1, int y1, int m2, int d2, int y2)
{
cout << "The First Calendar Date Request" << endl;
cout << "-------------------------------" << endl;
cout << "\n";
// Month combined with a conditional statement to prevent wrong input
cout << "Please enter the month: ";
cin >> m1;
if(m1 > 12 || m1 <= 0)
{
cout<<"Incorrect day entered"<<endl;
cin.ignore();
}
// Day combined with a conditional statement
cout << "Please enter the day: ";
cin >> d1;
if(d1 > 31 || d1 <= 0)
{
cout<<"Incorrect Month entered"<<endl;
cin.ignore();
}
//Year combined with a conditional statement
cout << "Please enter the year: ";
cin >> y1;
if(y1 > 9999 || y1 < 0)
{
cout<<"Incorrect Year Entered"<<endl;
cin.ignore();
}
cout << "\n";
cout << "The Second Calendar Date Request" << endl;
cout << "--------------------------------" << endl;
cout << "\n";
// Month combined with a conditional statement to prevent wrong input
cout << "Please enter the month: ";
cin >> m2;
if(m2 > 12 || m2 <= 0)
{
cout<<"Incorrect day entered"<<endl;
cin.ignore();
}
// Day combined with a conditional statement
cout << "Please enter the day: ";
cin >> d2;
if(d2 > 31 || d2 <= 0)
{
cout<<"Incorrect Month entered"<<endl;
cin.ignore();
}
//Year combined with a conditional statement
cout << "Please enter the year: ";
cin >> y2;
if(y2 > 9999 || y2 < 0)
{
cout<<"Incorrect Year Entered"<<endl;
cin.ignore();
}
}
|