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...
Thank you in advance
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..