How are these 2 sets of function with for loop different | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

13th Dec 2019, 4:45 PM
Joel Dong-Joe Suh
Joel Dong-Joe Suh - avatar
2 Answers
+ 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
13th Dec 2019, 9:05 PM
sneeze
sneeze - avatar
+ 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.
14th Dec 2019, 6:33 AM
Joel Dong-Joe Suh
Joel Dong-Joe Suh - avatar