|
From: Ioannis V. <no...@ho...> - 2002-08-06 04:25:53
|
<html><div style='background-color:'><DIV>
<P><FONT color=#000066>I suppose you mean why it doesn't stop pausing after you press Enter. Because it waits for some text input. A better way is to use cin.ignore():</FONT></P>
<P><FONT color=#000066></FONT> </P>
<P><FONT color=#000066>#include <iostream></FONT></P>
<P><FONT color=#000066>int main()<BR>{<BR> // --- iterate an integer by 2<BR> for (int i = 0; i <= 20; i+=2){<BR> std::cout << i << '\n'; <BR> <BR> }</FONT></P>
<P><FONT color=#000066> // --- pause system<BR> std::cin.ignore();<BR> <BR> return 0;<BR>}<BR></FONT></P>
<P><FONT color=#000066></FONT> </P>
<P><FONT color=#000066>However in MINGW 3.1 that i am using it needs two Enters to proceed which is not right (bug). I reported it to MINGW list. It should need only one.</FONT><BR><BR></P></DIV>
<DIV></DIV><BR><BR><BR>
<DIV><FONT color=#000066>Ioannis</FONT></DIV>
<DIV></DIV>
<DIV><FONT color=#000066></FONT> </DIV>
<DIV></DIV>
<DIV><FONT color=#000066></FONT></DIV>
<DIV></DIV>
<DIV><FONT color=#000066>* Ioannis Vranos </FONT></DIV>
<DIV></DIV>
<DIV><FONT color=#000066></FONT></DIV>
<DIV></DIV>
<DIV><FONT color=#000066>* Programming pages: </FONT><A href="http://www.noicys.cjb.net/"><FONT color=#000066>http://www.noicys.cjb.net</FONT></A></DIV>
<DIV></DIV>
<DIV><FONT color=#000066></FONT></DIV>
<DIV></DIV>
<DIV><FONT color=#000066>* Alternative URL: </FONT><A href="http://run.to/noicys"><FONT color=#000066>http://run.to/noicys</FONT></A></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>>From: tam...@ms...
<DIV></DIV>>To: <DEV...@LI...>
<DIV></DIV>>Subject: [Dev-C++] iterating by 2
<DIV></DIV>>Date: Mon, 5 Aug 2002 17:50:15 -0500
<DIV></DIV>>MIME-Version: 1.0
<DIV></DIV>>X-Originating-IP: [63.157.36.118]
<DIV></DIV>>Received: from mc1-f20.law16.hotmail.com ([65.54.236.27]) by mc1-s8.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.4905); Mon, 5 Aug 2002 16:08:31 -0700
<DIV></DIV>>Received: from usw-sf-list2.sourceforge.net ([216.136.171.252]) by mc1-f20.law16.hotmail.com with Microsoft SMTPSVC(5.0.2195.4905); Mon, 5 Aug 2002 16:04:59 -0700
<DIV></DIV>>Received: from usw-sf-list1-b.sourceforge.net ([10.3.1.13] helo=usw-sf-list1.sourceforge.net)by usw-sf-list2.sourceforge.net with esmtp (Exim 3.31-VA-mm2 #1 (Debian))id 17bqtR-00032M-00; Mon, 05 Aug 2002 16:04:05 -0700
<DIV></DIV>>Received: from oe156.pav0.hotmail.com ([64.4.33.149] helo=hotmail.com)by usw-sf-list1.sourceforge.net with esmtp (Exim 3.31-VA-mm2 #1 (Debian))id 17bqsf-0002DG-00for <DEV...@LI...>; Mon, 05 Aug 2002 16:03:17 -0700
<DIV></DIV>>Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 5 Aug 2002 16:02:12 -0700
<DIV></DIV>>Wrom: BXFGGMEPYOQKEDOTWFAOBUZXUWLSZLKBRNVW
<DIV></DIV>>X-Mailer: MSN Explorer 7.02.0005.2201
<DIV></DIV>>Message-ID: <OE1...@HO...>
<DIV></DIV>>X-OriginalArrivalTime: 05 Aug 2002 23:02:12.0103 (UTC) FILETIME=[22012970:01C23CD4]
<DIV></DIV>>Sender: dev...@li...
<DIV></DIV>>Errors-To: dev...@li...
<DIV></DIV>>X-BeenThere: dev...@li...
<DIV></DIV>>X-Mailman-Version: 2.0.9-sf.net
<DIV></DIV>>Precedence: bulk
<DIV></DIV>>List-Help: <mailto:dev...@li...?subject=help>
<DIV></DIV>>List-Post: <mailto:dev...@li...>
<DIV></DIV>>List-Subscribe: <HTTPS: dev-cpp-users listinfo lists lists.sourceforge.net>,<mailto:dev...@li...?subject=subscribe>
<DIV></DIV>>List-Id: Dev-C++ users mailing list <DEV-CPP-USERS.LISTS.SOURCEFORGE.NET>
<DIV></DIV>>List-Unsubscribe: <HTTPS: dev-cpp-users listinfo lists lists.sourceforge.net>,<mailto:dev...@li...?subject=unsubscribe>
<DIV></DIV>>List-Archive: <HTTP: redir-sf.php3?list="dev-cpp-users" www.geocrawler.com>
<DIV></DIV>>X-Original-Date: Mon, 5 Aug 2002 17:50:15 -0500
<DIV></DIV>>Return-Path: dev...@li...
<DIV></DIV>>
<DIV></DIV>>I have been tasked with a problem in my newbie manual to use a "for loop" and to console out by 2's from 0 to 20 here's what I have done and I was wondering 1st why it doesn't work and 2nd how do I make it work.
<DIV></DIV>>
<DIV></DIV>>#include <IOSTREAM>
<DIV></DIV>>int main()
<DIV></DIV>>{
<DIV></DIV>> // --- iterate an integer by 2
<DIV></DIV>> for (int i = 0; i <= 20; i+=2){
<DIV></DIV>> std::cout << i << '\n';
<DIV></DIV>>
<DIV></DIV>> }
<DIV></DIV>> // --- pause system
<DIV></DIV>> char end[5];
<DIV></DIV>> std::cin >> end;
<DIV></DIV>> return 0;
<DIV></DIV>>}
<DIV></DIV>>
<DIV></DIV>>Thanks in advance
<DIV></DIV>>Danny
<DIV></DIV></mailto:dev...@li...?subject=unsubscribe></mailto:dev...@li...?subject=subscribe></mailto:dev...@li...></mailto:dev...@li...?subject=help></div><br clear=all><hr>Chat with friends online, try MSN Messenger: <a href='http://g.msn.com/1HM1ENXX/c144??PS=47575'>Click Here</a><br></html>
|