Created
October 12, 2014 03:30
-
-
Save pizenblues/8f22f7136dca767421a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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_minutos(Tiempo& obj, int minutos){ | |
// si son mas de 60 añade tantas horas | |
// como quepan pa los minutos, ej: si | |
// pasan 160, eso es 2 hroas (120) | |
// y 40 minutos | |
if(obj.minutos + minutos >= 60){ | |
obj.horas += (int) minutos/60; | |
} | |
// aqui sacamos lo que resta de minutos | |
// 160%60 -> 40 | |
obj.minutos += (minutos%60); | |
} | |
void sumar_segundos(Tiempo& obj, int segundos){ | |
if(obj.segundos + segundos >= 60){ | |
obj.minutos += (int) segundos/60; | |
} | |
obj.segundos += (segundos%60); | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
Tiempo a = nuevo_tiempo(); | |
sumar_minutos(a, 400); | |
sumar_segundos(a, 90); | |
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