|
-
January 24th, 2009, 05:09 AM
#7
Re: How to exit a loop
 Originally Posted by Enfinik
I hope that explanation helped. Well here is the code:
Code:
#include <iostream>
#include <string>
using namespace std ;
int main()
{
int list[150] ;
int counter ;
int i ;
bool seventyTwo ;
counter = 0 ;
seventyTwo = true ;
for (i = 0 ; i < 150 ; i++)
{
while(seventyTwo) // While flag seventyTwo is true - loop
{
cout << "Enter an integer: " ;
cin >> list[i] ;
counter++ ; // Increments counter by a value of 1
if (list[i] == 72)
{
seventyTwo = false ; // Terminates loop upon entry of integer 72
}
} // End of while loop (inner)
} // End of outter for loop (outer)
return 0 ;
} // End of main

What is this supposed to do?
Your inner while loop will keep looping until the user enters 72 and on every loop it will overwrite the number in the list at position i. Then when the user enters 72, you exit the while loop BUT continue the for loop and this 150 times... doesn't sound right to me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|