Hey guys, first off I want to say thank you for all the help. I spoke to my professor after revising my code using the info you guys gave me.
Here is my code now:
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
|
#include <iostream>
using namespace std;
//define prototypes
int militaryToMinStrt(int);
int militaryToMinEnd(int);
int elapsedTime(int , int );
//universal constant
const int MINUTES_PER_HOUR = 60;
int main()
{
//define variables
int strtTime;
int endTime;
int minStrt;
int minEnd;
//prompt user to input start and end time
cout << "Please enter a start and end time for the same day in military time: ";
cin >> strtTime >> endTime;
//output time in minutes and output elapsed time
cout << "Your start time is: " << militaryToMinStrt(minStrt) << " minutes" << endl;
cout << "Your end time in minutes is: " << militaryToMinEnd(minEnd) << " minutes" << endl;
cout << "Your elapsed time in minutes is: " << elapsedTime(minStrt, minEnd) << " minutes"<< endl;
return EXIT_SUCCESS;
}
int militaryToMinStrt(int minStrt)
{
minStrt = ((strtTime / 100) * 60) + (strtTime % 100);
return minStrt;
}
int militaryToMinEnd(int minEnd)
{
minEnd = ((endTime / 100) * 60) + (endTime % 100);
return minEnd;
}
int elapsedTime(int strtTime, int endTime)
{
return (militaryToMinEnd(minEnd)) - (militaryToMinStrt(minStrt));
}
|
I made the variables being called inside the functions, universal variables. This made the code work perfect. But since my professor does not want that, and she said we would learn next week how to call a variable in a function that is in the main function, that I would not have to worry.
I also had to make
militaryToMinStrt
&
militaryToMinEnd
instead of using
miltaryToMin(int )
because when I would try to use the single function for 2 different calls, I would get an error saying I was trying to redefine
militaryToMin
. This makes perfect sense...
So all in all, I want to say thanks again for all the help because I truly do appreciate it. I have learned plenty from this post alone!
I will post on here how to call a variable from the main function when we learn. I am sure 95% of you people already know this, but I will do it for a personal preference and for those who stumble upon this post and don't know how to do it!
Thanks again! :)