Hi,
First let me start off by saying this is a homework assignment. It is my last one and I'm stuck. Below are the instructions provided by my professor and what I have come up with so far.
Where I'm stuck at is void keeps giving me an error, I have changed it around several times and I can get past it but then it tells me t wasn't declared.
I don't know why it doesn't work when the professor provides that as what to use.
I'm going to sleep but will be on tomorrow to see if anyone has explained why I'm getting an error any suggestions on how to get past it.
Thank You in advance.
Description
The program will input two different times, time 1 and time 2, from the user. The user may enter the two times in any order i.e. either of the two times may come before the other. The program will ask the user to input each time in hours, minutes, and seconds on a 24 hour clock so that the user won’t need not to specify am or pm. The program will find the difference between the two times. Then it will display the original two times and the difference between them. It will display the difference in hours, minutes, and seconds. It will do this repeatedly till user inputs a negative number when prompted to input hours for the first time.
Implementation
Use a structure Time to hold each of the two times. The structure Time will be made up of three components: int hour, int minute, and int second.
Create the following functions:
//input hour, minute, and second value and return Time
Time input ( ) {}
//display time into hour, minute, and second
void display (Time t) {}
//return the difference in second given two times.
int findDiff (Time t1, Time t2) {}
//convert second into Time
Time convert (int seconds) {}
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
|
#include <iostream>
using namespace std;
double time;
void display(Time t)
{
if (t.hour < 10)
cout << "0";
cout << t.hour;
cout << ":";
if (t.minute < 10)
cout << "0";
cout << t.minute;
cout << ":";
if (t.second < 10)
cout << "0";
cout << t.second;
cout << endl;
}
int Time(int, int, int);
int main(int argc, char** argv)
{int hours, minutes, seconds;
int T1 = 0;
int T2 = 0;
cout << "Input first clocktime...";
cout << "Hours: ";
cin >> hours;
cout << "Minutes: ";
cin >> minutes;
cout << "Seconds: ";
cin >> seconds;
T1 = Time(hours, minutes, seconds);
cout << "Input second clocktime...";
cout << "Hours: ";
cin >> hours;
cout << "Minutes: ";
cin >> minutes;
cout << "Seconds: ";
cin >> seconds;
cout<<"Time 1="<<T1<<endl;
cout<<"Time 2="<<T2<<endl;
T2 = Time(hours, minutes, seconds);
cout<<"Time 1="<<T1<<endl;
cout<<"Time 2="<<T2<<endl;
return 0;
}
int Time(int hours, int minutes, int seconds)
{
return hours*(3600) + minutes*(60) + seconds;
}
|