Loop troubles

IT repeats this loop like 5 times...why?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
                counter = 1;

		while ( counter <= totalSongs )
		{
		song = counter;
		cin >> songMinutes >> songSeconds;

		totalMinutes = totalMinutes + songMinutes;
		totalSeconds = totalSeconds + songSeconds;

			if ( totalSeconds >= SECONDS_IN_MINUTES )
			{
				totalMinutes = totalMinutes + ( totalSeconds / SECONDS_IN_MINUTES );
				totalSeconds = totalSeconds % SECONDS_IN_MINUTES;
			}
		
		cout << setw(6) << song << setw(15) << songMinutes
		<< setw(15) << songSeconds << setw(15) << totalMinutes
		<< setw(15) << totalSeconds << endl;

		counter++;

		}
I imagine it's because totalSongs has a value of six. The while condition in the parenthesis at the beginning is counter <= totalSongs. Each time through the loop you iterate counter: That is, you increase its value by one.

As long as counter isn't a larger value than totalSongs, that loops is gonna repeat. It's your condition.

Can you show us the part of your code where you assign a value to totalSongs?
Last edited on
it depends on value of 'totalSongs'

 
while ( counter <= totalSongs )
Topic archived. No new replies allowed.