Skip to content

Instantly share code, notes, and snippets.

@krlicmuhamed
Created July 11, 2015 18:27
Show Gist options
  • Save krlicmuhamed/07f87b317eda9a52bcf6 to your computer and use it in GitHub Desktop.
Save krlicmuhamed/07f87b317eda9a52bcf6 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
// Exercise 12-2: Design a structure to store time and date. Write a function to find the difference
// between two times in minutes.
struct datetime{
int seconds;
int minutes;
int hours;
int day;
int month;
int year;
};
datetime new_datetime(int h, int m, int s, int d, int M, int y){
struct datetime date = {
s,
m,
h,
d,
M,
y
};
return date;
}
struct date {
int day;
int month;
int year;
};
struct time {
int seconds;
int minutes;
int hours;
};
time extract_time_from_datetime(datetime dt){
struct time _time = {
dt.seconds,
dt.minutes,
dt.hours
};
return _time;
}
int main() {
datetime today = new_datetime(17, 52, 0, 11, 7, 2015);
cout << today.year << endl;
time t = extract_time_from_datetime(today);
cout << t.hours;
return 0;
}
/*
Stack trace:
/cygdrive/c/Projects/C++/Exercises/PracticalC++1995/Exercise12-2/main.cpp:41:1: error: 'time' does not name a type
time extract_time_from_datetime(datetime dt){
^
/cygdrive/c/Projects/C++/Exercises/PracticalC++1995/Exercise12-2/main.cpp: In function 'int main()':
/cygdrive/c/Projects/C++/Exercises/PracticalC++1995/Exercise12-2/main.cpp:54:10: error: expected ';' before 't'
time t = extract_time_from_datetime(today);
^
/cygdrive/c/Projects/C++/Exercises/PracticalC++1995/Exercise12-2/main.cpp:55:13: error: 't' was not declared in this scope
cout << t.hours;
^
CMakeFiles/Exercise12_2.dir/build.make:54: recipe for target 'CMakeFiles/Exercise12_2.dir/main.cpp.o' failed
make[3]: *** [CMakeFiles/Exercise12_2.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/Exercise12_2.dir/all' failed
make[2]: *** [CMakeFiles/Exercise12_2.dir/all] Error 2
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/Exercise12_2.dir/rule' failed
make[1]: *** [CMakeFiles/Exercise12_2.dir/rule] Error 2
Makefile:109: recipe for target 'Exercise12_2' failed
make: *** [Exercise12_2] Error 2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment