Hello, I am a total beginner struggling through my first class with c++. My first project involves prompting a user for the name of an event, along with how many seconds after July 1st, 2015 the event took place. The program should then determine what day of the month the time points to, and the time of day (military time) the event took place.
I am required to create separate functions to calculate from seconds to the end result date/time.
Main issues I am having:
-Not sure how to correctly declare the start date of July 1st, 2015.
-Not sure how to calculate from the user input of seconds to desired output of minutes, hours, days, date, etc...
My current code is an absolute mess, as I have been frantically messing around with it to produce something useful for me. To be honest, I am considering starting over from scratch.
Any help or advise is greatly appreciated!
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
|
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
double seconds;
double remainderseconds;
double minutes;
double hours;
double remainderhours;
double days;
double endDate;
string beginTime;
string endTime;
string eventName;
void SetStartDate(const int day, const string month, const int year);
void secondspast ();
void calculateminutes ();
void calculatehours ();
void calculatedays ();
void SetStartDate(const int day, const string month, const double year) {
day = 1;
month = July;
year = 2015;
}
void secondspast () { //Prompt question of how many seconds past start date
cout << "How many seconds past July 1st, 2015 does " << endl;
cout << eventName << endl;
cout << "take place?";
}
void calculateminutes () { //Function calculates the minutes past July 1st, 2015 based on seconds
minutes = seconds / 60;
remainderseconds = seconds % 60;
}
void calculatehours () { //Function calculates the hours past July 1st, 2015 based on minutes
calculateminutes ();
hours = minutes / 60;
remainderhours = minutes % 60;
}
void calculatedays () { //Function calculates days past July 1st, 2015 based on hours
calculatehours ();
days = hours / 24;
}
int main() {
cout << "What is the name of the event?"; //Prompt user for name of event
getline ( cin, eventName ) ; //Program takes in name and stores it in eventName
cout << endl; //Skip line
secondspast (); // Call secondspast function from main
cin >> seconds; //Program takes in user input from secondspast function and stores it in seconds
calculateminutes (); //Call calculateminutes function from main
calculatehours (); //Call calculatehours from main
calculatedays (); //call calculatedays from main
endDate = ??
cout << endl; //Skip line
cout << eventName << " takes place on " << endDate << " at " << endTime << endl; //Display event endDate and endTime to user
return 0;
}
|