5
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("\tPrograma para saber quanto demora a tornar-se génio!\n\n");
float tempo(int horas);
float converter(float x);
int num_horas;
float dias,anos;
printf("Quantas horas vai dedicar por dia para ser genio?");
scanf("%d",&num_horas);
dias=tempo(num_horas);
anos=converter(dias);
printf("Voce vai demorar %.1f dias ou seja aproximadamente %.2f anos para ficar génio",dias,anos);
return 0;
}
//funcao para converter dias em anos
float converter(float x) {
if(x>366) {
int um_ano=366;
float troca=x/um_ano;
return troca;
}
}
//funcao que converte as horas dedicadas em dias;
float tempo(int horas) {
float dias;
dias=10000/horas;
return dias;
}
The code works, but I wanted to improve on that part when it does printf
and says how many years it takes to be a genius. He makes a float
(on purpose), but I wanted to convert the decimal part into months. For example 4.22 years, I wanted it to stay 4 years and I don’t know how many months(.22).
I accept constructive criticism.
Can you explain this part? (1.0f / 12.0f) + 1; I did not understand very well. Otherwise it is ok.
– Toshiyuki
This part is just math, there’s nothing programming, I did what you asked, turn decimal into months, just add 1 to round up and not create an expectation that time would be lower than it really is.
– Maniero