why this coding dont work

when i input 1 hrs and 0 mins, sec. it come bk 1, but it should be 3600
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  #include <stdio.h>
#include <math.h>
int secs(int, int, int);	/*function prototype statement*/

int main()

{
	/*variable to store time; hour, min and sec*/
	int hr, min, sec, time;
	/*Function prototype*/
	int secs(int, int, int);
	
	printf("Enter a Number of hours: ");
	scanf("%d", &hr);
	
	printf("Enter a Number of hours: ");
	scanf("%d", &hr);
	
	printf("Enter a Number of hours: ");
	scanf("%d", &hr);
	
	/*function calling statement*/
	time = secs(hr, min, sec);	
	
	printf("The total no. of seconds ... %d\n", time);
	
	return 0;
}

int secs(int h, int m, int s)
{
	int total;
	total = h*60*60+m*60+s;
	return (total);
	
}
min/sec remain uninitialized. scanf(...) uses only hr. See line 17/20
1
2
3
4
5
6
7
8
printf("Enter a Number of hours: ");
	scanf("%d", &hr);
	
	printf("Enter a Number of hours: ");
	scanf("%d", &hr);
	
	printf("Enter a Number of hours: ");
	scanf("%d", &hr);


You always put your input inside hours. So by inputing 1 0 0, it will eventually be 0.
Topic archived. No new replies allowed.