#include <iostream> #include <iomanip> #include "C1A7E1_MyTime.h" using namespace std; MyTime *DetermineElapsedTime(const MyTime *tp1, const MyTime *tp2); int main() { for (int loop_count = 0; loop_count < 3; loop_count++) { cout << "Enter time point one, space separated:\n"; cin >> tm1.hours >> tm1.minutes >> tm1.seconds; cout << "Enter time point one, space separated:\n"; cin >> tm2.hours >> tm2.minutes >> tm2.seconds; cout << "entering function!"; DetermineElapsedTime(const tm1, const tm2) } const MyTime tm1 = { 2, 0, 0}; const MyTime tm2 = { 0, 0, 0}; MyTime time_dif = *DetermineElapsedTime(&tm1, &tm2); cout << "The time elapsed from "; cout << setfill('0') << setw(2) << tm1.hours << ":"; cout << setfill('0') << setw(2) << tm1.minutes << ":"; cout << setfill('0') << setw(2) << tm1.seconds; cout << " to "; cout << setfill('0') << setw(2) << tm2.hours << ":"; cout << setfill('0') << setw(2) << tm2.minutes << ":"; cout << setfill('0') << setw(2) << tm2.seconds; cout << " is "; cout << time_dif.hours << ":" << time_dif.minutes << ":" << time_dif.seconds << "\n"; } C1A7E1_MyTime.h #ifndef Class_Test_C1A7E1_MyTime_h #define Class_Test_C1A7E1_MyTime_h using namespace std; struct MyTime { int hours, minutes, seconds; }; /* do not change this */ #endif C1A7E1_DetermineElapsedTime.cpp #include <iostream> #include "C1A7E1_MyTime.h" using namespace std; MyTime *DetermineElapsedTime(const MyTime *tp1, const MyTime *tp2) { static MyTime return_time; MyTime testy1, testy2; testy1 = *tp1; testy2 = *tp2; long time_point_dif; time_point_dif = (long(testy1.hours) * 3600 + long(testy1.minutes) * 60 + long(testy1.seconds)) - \ (long(testy2.hours) * 3600 + long(testy2.minutes) * 60 + long(testy2.seconds)); return_time.hours = int(time_point_dif / 3600); time_point_dif -= return_time.hours * 3600; return_time.minutes = int(time_point_dif / 60); time_point_dif -= return_time.minutes * 60; return_time.seconds = int(time_point_dif); return(&return_time); }
for
const
const MyTime tm1 = { 2, 0, 0}; const MyTime tm2 = { 0, 0, 0};
DetermineElapsedTime(const tm1, const tm2)
Quote:I tried to create data type int tm1, tm2? Not sure why I am getting an error not in scope.
tm1
tm2
Quote:Yes but what do I do about it I have tried to declare the variable before hand and it still does not work?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)