C++ Program Arisan Randomize (CPAR)

Create a program for a social gathering, with the provision that the number of members or participants who join is inputted manually in the first step, and for the draw it is no longer done manually using a spittoon or rolled paper, but is randomized automatically, please create the program using c++ with arrays.


Participant Input


Randomize output

Source code:

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>

/**
*bundet.com
*Program Arisan
*/

void main(){
int jml, i, arisan[100], undian[100], x;
cout << "banyaknya peserta arisan : "; cin >> jml;

randomize;
for (int i=0; i<jml; i++){
arisan[i]=random(jml+1);

if (i !=0){
do{
 arisan[i]=random(jml+1);
   x=0;
   for (int j=0; j<i; j++) {
    if (arisan[i]==undian[j]){
      x++;
      }
   }
}while (x>0 || arisan[i]==0);
cout<<"undian arisan ke-"<<i+1<<": "<<arisan[i]<<endl;
undian[i]=arisan[i];
}

else{
cout<<"undian arisan ke-1: "<<arisan[0]<<endl;
undian[0]=arisan[0];
}
}
getch();
}

Hope this is useful & happy learning!

Question 1

AKHI ROZIKIN Mar 12, 2017, 19:57:00 bro, a little suggestion, try each script, give an explanation of how it works, especially the logic part, hehe,,, college assignment, wkwkwkk, thanks bro

HAYFA TSURAYYA Nov 26, 2017, 22:24:00 Why aren't randomize and random() declared when run? Even though I've copied and pasted..

Response 1

Hii AKHI ROZIKIN, okay, thanks for your input, in the future if I have time I will try to perfect every script available on this blog with an explanation and how it works.

So far the code still works when run in Borland C++, if you still experience problems/errors, please attach a screenshot of the error here, I will try to help as much as possible.


Post a Comment

Previous Next

نموذج الاتصال