fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main(void) {
  8. int maxball;
  9. int ballsno;
  10.  
  11. cout << "Max ball number? ";
  12. cin >> maxball;
  13. cout << "How many balls? ";
  14. cin >> ballsno;
  15. srand(time(NULL));
  16.  
  17. bool *array=new bool[maxball], rnd;
  18. for (int i=0;i<ballsno;i++)
  19. {
  20. do
  21. {
  22. rnd=rand()%max+1;
  23. } while (array[rnd]);
  24. array[rnd]=true;
  25. cout<<rnd;
  26. }
  27.  
  28. delete[] array;
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22:23: error: invalid operands of types ‘int’ and ‘<unresolved overloaded function type>’ to binary ‘operator%’
             rnd=rand()%max+1;
                 ~~~~~~^~~~
stdout
Standard output is empty