For Loop + Arrays problem

I got a problem about the program...

This is the sample output->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1. Cars: AA11 
Hours: 2

2. Cars: BB22 
Hours: 4

3. Cars: CC33 
Hours: 6

4. Cars: DD44 
Hours: 8

5. Cars: EE55 
Hours: 10



This is my coding->

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream.h>

void main ()
{
	char cname[5];
	int n, hour;

	for (n=1; n<=5; n++) {
		cout << n << ". Cars: ";
		cin.getline(cname, 5);
		cout << "Hours: ";
		cin  >> hour;
		cout << endl;
	}
}




This is my output->
1
2
3
4
5
6
7
8
9
1. Cars: AA11
Hours: 2

2. Cars: Hours: BB22

3. Cars: Hours:
4. Cars: Hours:
5. Cars: Hours:
Press any key to continue_
Cin ignore end of line value. You read the end of line in next getline. You can use cin.ignore(1000, "\n")
Last edited on
Topic archived. No new replies allowed.