# Thread: Need help with program

1. ## Need help with program

Hello, I'm new to this forum, but I need help really bad and can't seem to figure out how to fix my overflow problem.

I'm taking a class where I have to write a program that calculates a given number of seconds and generates how many centuries, years, days, hours, and minutes that given number is. The output needs to be displayed in a table with the given numbers written above it, but at the moment I'm still trying to figure out the overflow issue and I'm using a user input of any number of seconds to give me an answer and I can't even seem to get it to do that... any help is MUCH appreciated...

Alex.
Code:
```/***********
* Alex Carpenter
* ACCarpenter
* CS1300/project 2/Path_Length
* Due Date: September 7, 2011
* A program created to calculate an "x" amount of seconds
* into minutes, hours, days, years, and centuries.
***********/
#include <stdio.h> /* use standard I/O functions */

int main ()
{ /*begin main */

const int seconds_in_centuries = 3153600000;
const int seconds_in_years = 31536000;
const int seconds_in_days = 86400;
const int seconds_in_hours = 3600;
const int seconds_in_minutes = 60;

long long int centuries;
long long int years;
long long int days;
long long int hours;
long long int minutes;

/*calculates number of centuries-minutes the amount of seconds equals*/
centuries=seconds/seconds_in_centuries;
years = years % seconds_in_centuries;
days = days % seconds_in_years;
hours = hours % seconds_in_days;
minutes = minutes % seconds_in_hours;
seconds = seconds % seconds_in_minutes;

printf("How many seconds?");
scanf("%llu",&seconds);
printf("%llu",seconds);
return 0;
}```

remember i just started learning this so we haven't advanced to anything past the basics..

2. > const int seconds_in_centuries = 3153600000;
This overflows an int on a 32-bit machine.

How about declaring everything as a long long int ?

Also, which compiler are you using?

> /*calculates number of centuries-minutes the amount of seconds equals*/
Do these AFTER reading in a value for seconds.

3. Originally Posted by Salem
> const int seconds_in_centuries = 3153600000;
This overflows an int on a 32-bit machine.

How about declaring everything as a long long int ?

Also, which compiler are you using?

> /*calculates number of centuries-minutes the amount of seconds equals*/
Do these AFTER reading in a value for seconds.
Wow thank you for the very fast reply! I'm using jgrasp to actually write my code but we are using a linux server to compile everything..

4. ## Anyone?

I still need help with this... I really just need to get it to convert seconds into centuries, and I can't figure out what i'm doing wrong...

5. Well posting your latest code would be a start.
What thing(s) did you do following the previous suggestions.
We can't see your screen - remember.

6. Originally Posted by alex33zebras
I still need help with this... I really just need to get it to convert seconds into centuries, and I can't figure out what i'm doing wrong...