Stonewall382
Knight at Arms

Hey guys, I got bored and decided to write a program in C++ (I'm learning C++ in a class right now, and am working to write a game). I figured we could all use a break from the religion and racism threads, so if you feel like it, try it out (and please tell me what you think).
You'll need the HiC complier, which can be found by Googling "Hasker HiC" (I'm not sure if I'm allowed to give a direct link from the University website, so I won't). Once you get it, paste this code into it, and hit F9 (or the green arrow):
(I know it's messy, but I didn't feel like making functions for the two options, because we haven't learned data structures yet, so the function calls would be messy as ****.)
Edit: Like I said, I'm not sure if the free compiler can be used by people not in a course at some institution, but I don't know why this would be a problem. Mods, if you don't like it, feel free to close the thread. Here's the quote (from the HiC website) that may cause problems:
You'll need the HiC complier, which can be found by Googling "Hasker HiC" (I'm not sure if I'm allowed to give a direct link from the University website, so I won't). Once you get it, paste this code into it, and hit F9 (or the green arrow):
(I know it's messy, but I didn't feel like making functions for the two options, because we haven't learned data structures yet, so the function calls would be messy as ****.)
Edit: Like I said, I'm not sure if the free compiler can be used by people not in a course at some institution, but I don't know why this would be a problem. Mods, if you don't like it, feel free to close the thread. Here's the quote (from the HiC website) that may cause problems:
HiC, developed by Robert W. Hasker, is freely available for use by institutions of up to 15,000 students for on-campus (traditional) courses, though instructors should contact the author to get on a mailing list for updates. This mailing list will have very low traffic, and email addresses will not be shared with commercial organizations under any circumstances. Larger institutions, and instructors and students of online/distance courses must contact the author for permission to use HiC.
插入代码块:
/* Written by [Stonewall382] March 12, 2007
1st part written from ~ 11:00 to ~ 11:45.
reg2 written from ~ 11:50 to ~ 12:10.
*/
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int const MINUTES = 60;
int const HOURS = 60 * MINUTES;
int const DAYS = 24 * MINUTES;
int const WEEKS = 7 * DAYS;
int const YEARS = 365.25 * DAYS;
int Month (string month);
int MonthInSeconds (int);
string OutputZero (int);
void main()
{
int monthNumber1, day1, year1, hours1, minutes1, seconds1, sum,
monthNumber2, day2, year2, hours2, minutes2, seconds2,
yearsPassed, weeksPassed, daysPassed, hoursPassed, minutesPassed,
secondsPassed,
difference, reg1;
string month1, month2, at, AND;
char comma, colon;
cout << "An example date would look like this:\n" <<
"March 13, 2007, at 0:13 and 4.\n" <<
"(This means March 13, 2007 at 12:13\n" <<
"and four seconds in the a.m.)\n\n";
sleep(2);
while ( ! cin.eof())
{
cout << "1 for seconds between year 0 and a date, or\n" <<
"2 for time between one date and another:\n";
cin >> reg1;
if (reg1 == 1)
{
cout << "Enter the month, day, year,\nand time (hours, minutes, seconds)" <<
"\nin military format:\n";
cin >> month1 >> day1 >> comma >> year1 >> at >>
hours1 >> colon >> minutes1 >> AND >> seconds1;
monthNumber1 = Month (month1);
sum = (year1 * YEARS) + (monthNumber1 * MonthInSeconds (monthNumber1)) + (day1 * DAYS) +
(hours1 * HOURS) + (minutes1 * MINUTES) +
seconds1;
cout << "\n\n" << sum << " seconds have passed\n" <<
"between midnight January 1st, year 0 and\n" << month1 <<
" " << day1 << ", " << year1 << " at time " << hours1 <<
":" << OutputZero (minutes1) << minutes1 << " and " << seconds1 << " seconds.\n\n";
}
else
{
cout << "Enter the earlier date:\n";
cin >> month1 >> day1 >> comma >> year1 >> at >>
hours1 >> colon >> minutes1 >> AND >> seconds1;
cout << "\nEnter the later date:\n";
cin >> month2 >> day2 >> comma >> year2 >> at >>
hours2 >> colon >> minutes2 >> AND >> seconds2;
monthNumber1 = Month (month1);
monthNumber2 = Month (month2);
difference = ((year2 * YEARS) + (monthNumber2 * MonthInSeconds (monthNumber2)) +
(day2 * DAYS) + (hours2 * HOURS) + (minutes2 * MINUTES) + seconds2) -
((year1 * YEARS) + (monthNumber1 * MonthInSeconds (monthNumber1)) +
(day1 * DAYS) + (hours1 * HOURS) + (minutes1 * MINUTES) + seconds1);
yearsPassed = difference / YEARS;
difference /= YEARS;
weeksPassed = difference / WEEKS;
difference /= WEEKS;
daysPassed = difference / DAYS;
difference /= DAYS;
hoursPassed = difference / HOURS;
difference /= HOURS;
minutesPassed = difference / MINUTES;
difference /= MINUTES;
secondsPassed = difference;
cout << "\n\n" << yearsPassed<< " years, " << weeksPassed << " weeks, " <<
daysPassed << " days, " << hoursPassed << " hours, " <<
minutesPassed << " minutes, and " << secondsPassed << " seconds\n" <<
"passed between " << month1 << " " << day1 << ", " << year1 << " at " <<
hours1 << ":" << OutputZero (minutes1) << minutes1 << " and "
<< seconds1 << " seconds, and\n" <<
"passed between " << month2 << " " << day2 << ", " << year2 << " at " <<
hours1 << ":" << OutputZero (minutes2) << minutes2 << " and " <<
seconds2 << " seconds";
}
cout << "\n\n";
}
}
string OutputZero (int minutes)
{
string bah;
if (minutes < 10)
bah = "0";
return (bah);
}
int Month (string month)
{
int monthNum;
if (month == "January")
monthNum = 1;
else if (month == "February")
monthNum = 2;
else if (month == "March")
monthNum = 3;
else if (month == "April")
monthNum = 4;
else if (month == "May")
monthNum = 5;
else if (month == "June")
monthNum = 6;
else if (month == "July")
monthNum = 7;
else if (month == "August")
monthNum = 8;
else if (month == "September")
monthNum = 9;
else if (month == "October")
monthNum = 10;
else if (month == "November")
monthNum = 11;
else if (month == "December")
monthNum = 12;
return (0);
}
int MonthInSeconds (int month)
{
int monthInSeconds;
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
monthInSeconds = 31 * DAYS;
else if (month == 2)
monthInSeconds = 28 * DAYS;
else
monthInSeconds = 30 * DAYS;
return monthInSeconds;
}


