CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    1

    How to exit a loop

    I am doing a homework assignment in which we have to get an undetermained amount of numbers from the user. I was wondering how to tell when the user is done entering numbers and wants to exit the loop, such as perhaps a blank space or a word like 'quit'.

    Here is what I have so far, I used 72 as the exit number just as a test.
    Code:
    // Function Used to Get Numbers into Array
    int  calcList() {
    
    	for (int i=0; i<100; i++) {
    		std::cout << "Enter an integer: ";
    		 std::cin  >> list[i];
    		 counter = counter + 1;
    		 
    		 // Exit Loop When 72 is Inputed
    		 if (list[i]== 72) {
    			 return(0);
    		 }
    		 
    	}
    }
    Thank you.
    Last edited by Andreas Masur; January 18th, 2009 at 10:06 PM. Reason: Added code tags...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured