Error

I don't understand what's happening??

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
37
38
39
 #include<iostream>
using namespace std;
struct time
{
	int hours;
	int minutes;
	int seconds;
}time 1[2];
void addtime (time,time)

main()
{
	int sec;
	for(int i=0;i<=1;i++)
{
	cout<<"\nEnter the time"<<i+1<<"\n";
	cout<<"Hours:";
	cin>>time 1[i].hours;
	cout<<"Minutes";
	cin>>time 1[i].minutes;
	cout<<"Seconds:";
	cin>>time 1[i].seconds;
}
	addtime(time 1[0],time 1[1]);
}
void addtime(time t1,time t2)
{
	int sec,min,hr,x;
	sec=t1.seconds+t2.seconds;
	x=sec/60;
	sec%=60;
	min=t1.minutes+t2.minutes+x;
	hr=t1.hours+t2.hours+min/60;
	min%=60;
	cout<<"\nThe total time in hh mm ss format is:\n";
	cout<<"\nHours:"<<hr;
	cout<<"\nMinutes:"<<min;
	cout<<"\nSeconds:"<<sec;
}
Last edited on
Lines 8,18,20,22,24
time 1
That's not a valid identifier.
I write a program that declares a structure time to store hours,minutes and seconds.
that program declares an array of this structure and inputs two times from user.It adds both time and displays the total time and in hh mm ss format
Last edited on
Hi,

Put a semicolon at the end of line 9, because it's a function declaration.

It's illegal to have an identifier (variable or function name) starting with a number.

Prefer to use a std::vector rather than an array. You could create this in main, rather than a global.

Choose an indenting style and stick with it, make sure the placement of the braces makes sense. With a for loop, it's usual to line up the braces with the f in the keyword for. That makes the code easier to read. This site converts tabs to 8 spaces, and it is good practice to use spaces instead of tabs in your editor, so code displays better when it is viewed elsewhere.
main()

While we're here, that's very wrong. main returns an int:

int main()
Topic archived. No new replies allowed.