Skip to content

Instantly share code, notes, and snippets.

@pizenblues
Last active August 29, 2015 14:07
Show Gist options
  • Save pizenblues/ed3f20377270ffa1739d to your computer and use it in GitHub Desktop.
Save pizenblues/ed3f20377270ffa1739d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
using namespace std;
struct Tiempo
{
int horas;
int minutos;
int segundos;
};
/** esto cambiará luego :3 */
Tiempo nuevo_tiempo(){
Tiempo x = Tiempo();
x.horas = 0;
x.minutos = 0;
x.segundos = 0;
return x;
}
void sumar_horas (Tiempo& obj, int horas){
if(obj.horas + horas >= 24){
//obj.horas += (int) horas/24;
obj.horas = (horas+obj.horas)%24;
}
//obj.horas += (horas%24);
}
void sumar_minutos(Tiempo& obj, int minutos){
if(obj.minutos + minutos >= 60){
obj.horas += (int) minutos/60;
}
obj.minutos += (minutos%60);
}
void sumar_segundos(Tiempo& obj, int segundos){
if(obj.segundos + segundos >= 60){
sumar_minutos (obj, (int) segundos/60);
}
obj.segundos += (segundos%60);
}
int main(int argc, char const *argv[])
{
Tiempo a = nuevo_tiempo();
sumar_horas(a, 20);
sumar_minutos(a, 400);
//sumar_segundos(a, 7230);
printf("%i:%i | %i\n", a.horas, a.minutos ,a.segundos);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment