Nested loop logic error with temporary logic error

The output displays only the time from 7 to 11:59. It is estimated that it will be from noon to midnight. Its a logical mistake, but I can’t find a way to fix it.

#include <iostream> using namespace std; int main () { int hour,min; for (hour=0;hour<=11;hour+=1) { for (min=0;min<=59;min++) { if (min<10) cout<<hour<<":"<<"0"<<min<<endl; else cout<<hour<<":"<<min<<endl; } } return 0; } 
+4
source share
1 answer

The Windows console is configured to display by default no more than 300 lines of scrolling (output).

7 is 5 hours behind 12 and 5 * 60 = 300. Therefore, you most likely see the limit of your scroll buffer.

Increase the size of your scroll (right-click on the command line icon, select properties-> layout, set the scroll to something higher, for example 9999), or write your output to a file. You will see the correct conclusion.

+2
source

Source: https://habr.com/ru/post/1440180/


All Articles