Thread: Some exercises
View Single Post
Old Jun 29th, 2005, 8:01 PM   #1
deathseeker25
Programmer
 
Join Date: May 2005
Posts: 48
Rep Power: 0 deathseeker25 is on a distinguished road
Some exercises

Hello I'm a n00b ate programming and I think I need some help solving one exercise that I saw in a Google search.It says exactly:

Quote:
1. To write a program that reads 3 corresponding whole number to one hour in hours, minutes and seconds, and converts into seconds, and prints the result. Assuming the following 0 variable for the hours, minutes and seconds, the reading could be:

int horas, minutos,segundos;
long int result_em_segundos;
.....
scanf("%d%d%d",&horas, &min, & seg);
Note: this was translated by Google....

Well this problem was solved almost successfully:

/*Horas. minutos e segundos*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int horas,min,seg;
    long int result_em_segundos;
    
    printf("\nDiga que horas, quantos minutos e quantos segundos são respectivamente: ");
    scanf("%d%d%d",&horas,&min,&seg);
    
    horas=60*60*horas;
    min=60*min;
    
    printf("O resultado em segundos e de %d ",horas+min+seg);
    
    
    system("PAUSE");

Some things are in portuguese btu I think the code is quite understandable...

Well, my big problem is the second exercise:

Quote:
2. write a program that makes the inverse operation in the previous exercice.
And I wrote this code:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int horas,sec,min;
    
           
    printf(" Say how many seconds you intend to convert for hourly time....");
    scanf("%d",&sec);
    
    horas=sec/60/60;
    min=sec/60;
    
    printf("Sao %d horas %d minutos e %d segundos",horas,min,sec);
    
    system("PAUSE");
    
}
The problem is that after compiling and executing it appears the following one in relation the last printf, introducing as given 3600 seconds:

Quote:
It's 1 hour, 60 minutes and 3600 seconds
Well, this is quite bad, isn't it....help me please....
deathseeker25 is offline   Reply With Quote