Hi friends :P
I'm needing some help on an assignment. I'm really not sure about all the argument-passing and structure references I have been assigned for my C++ class. Any help is greatly appreciated. I'll continue to work on it in the meantime, but I cannot get it to compile yet without any errors. Thank you!
// -----------------------------------------------------------------
// This program asks the user for two different time values and
// returns the sum as the 'result'. The user is able to enter an
// unlimited number of cases and each one's results.
// -----------------------------------------------------------------
#include <iostream>
using namespace std;
struct Time //declare Time structure
{
int Hours; //Hour of Time
int Minutes; //Minute of Time
int Seconds; //Second of Time
}; //Necessary semi-colon
//declarations
void Input_Time(Time&, int, int, int); //Inputs the time value & returns it using a reference parameter
Time Input_Time(int, int, int); //Inputs the second time value & returns it using the "return" statement
long Time_To_Seconds(Time, Time); //Accepts a time value and returns a code indicating valid or invalid data
Time Seconds_To_Time(long); //Accepts a time value for printing and returns nothing
int Validate_Time(Time); //Accepts time value and returns the total seconds
void DisplayTime(Time); //Accepts total seconds and returns a time value in hours, minutes, seconds
void Print_Zero(int);
int main()
{
Time t1, t2, t3, final;
long totalSeconds;
cout << endl
<< "This program will input two times in HR:MN:SC " << endl
<< "and output the sum of both in HR:MN:SC." << endl
<< endl;
for(case=1; case < 9999; case++;)
{
t1 = Input_Time(Time&, int)
t2 = Input_Time()
totalSeconds = Time_To_Seconds(Time t1, Time t2); //sum of t1 & t2
cout << endl;
cout << "\nTime 1: "; DisplayTime(t1);
cout << "\nTime 2: "; DisplayTime(t2);
cout << "\nResult: "; DisplayTime(final);
cout << endl;
return 0;
}
}
void Input_Time(Time&)
{
cout << "Time 1: ";
cin >> t1.hours >> t1.Minutes >> t1.Seconds;
}
Time Input_Time()
{
cout << "Time 2: ";
cin >> t2.Hours >> t2.Minutes >> t2.Seconds;
return t2;
}
//Time_To_Seconds()
//Accepts two Time structures and returns the sum of total seconds as a long datatype
long Time_To_Seconds(Time t1, Time t2)
{
Time t3,
long totalSeconds; //define a new structure for sum
t3.Seconds = t1.Seconds + t2.Seconds; //add the seconds
t3.Minutes = (60*(t1.Minutes + t2.Minutes));//add the minutes and convert to seconds
t3.Hours = (3600*(t1.Hours + t2.Hours)); //add the hours and convert to seconds
totalSeconds = t3.Hours + t3.Seconds + t3.Minutes;
}
Time Seconds_To_Time(long totalSeconds)
{
Time final;
if(totalSeconds >= 3600)
{
totalSeconds -= 3600;
final.Hours++;
}
if(totalSeconds >= 60)
{
final.Seconds -= 60;
final.Minutes++;
}
return final;
}
//Validate_Time()
int Validate_Time(Time final)
{
int 0, 1;
if
{
final.Hours > 23 || final.Minutes > 59 || final.Seconds > 59;
cout << "1";
}
else
{
cout << "0";
}
return;
}
//DisplayTime()
//Display structure of type Time in Hours, Minutes, and Seconds
void DisplayTime(Time) //time tt of type Time
{
cout << tt.Hours << "\n:" << tt.Minutes << "\n:" << tt.Seconds << "\n:";
}
void Print_Zero(int) //Accepts an hour, minute, or second value,
//and prints only a zero if the value is < 10.
//If the value passed is > 10, nothing is printed.
//Called from Display_Time()