Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC