Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace UTS2
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. int[] Dadu1 = new int[7];//membuat array dadu 1
  23. int[] Dadu2 = new int[7];//membuat array dadu 2
  24. int lempar;//inisialisasi lempar
  25. int lemparan = Int16.Parse(textBox1.Text);//inisialisasi lemparan
  26. Random roll = new Random();//RNG
  27. for (lempar = 1; lempar <= lemparan; lempar ++)//looping statement
  28. {
  29. Dadu1[roll.Next(1, 7)]++;//RNG
  30. Dadu2[roll.Next(1, 7)]++;//RNG
  31. }
  32.  
  33. for (int side = 1; side < Dadu1.Length; side++)//looping statemnet
  34. {
  35.  
  36. textBox2.Text+=(Dadu1[side])+" ";//output ke textbox per roll
  37. }
  38. for (int side = 1; side < Dadu2.Length; side++)//looping statement
  39. {
  40.  
  41. textBox3.Text+=(Dadu2[side])+" ";//output ke textbox
  42. }
  43. int total = Dadu1.Sum() + Dadu2.Sum();//aritmarika total jumlah sisi dadu
  44.  
  45. textBox4.Text=Convert.ToString(total);//output ke textbox
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement