+ 1
How are these 2 sets of function with for loop different
Wrote a function with 2 for loops but each giving different output but they should output the same if I'm not mistaken https://code.sololearn.com/cJgWkuuW2W8Z/?ref=app
2 ответов
+ 2
In the second the stament cout<<endl; is not included in the for-loop. That causes all results to be printed on one line.
second loop
}// not included
cout<<endl;
versus
first loop endl before } so endl is included in loop
cout<<endl; //<<this
}
also
cout<<rand()%<<" ";
in this line a 2 is missing
if you leave the % there is an error
if you do rand() is gives random numbers which are not 0 or 1
keep asking, keep coding
+ 1
Thanks for the explanation. It seems I just got to add { } to the loop. The rand()% typo wasn't part of the question but thanks for pointing it out. Gotta double check my word.