عرض مشاركة واحدة
منتديات طلاب وطالبات جامعة الملك عبد العزيز منتديات طلاب وطالبات جامعة الملك عبد العزيز
  #1  
قديم 24-02-2013, 03:04 PM

jojo f jojo f غير متواجد حالياً

جامعي

 
تاريخ التسجيل: Mar 2012
التخصص: حاسب
نوع الدراسة: إنتظام
المستوى: الرابع
الجنس: أنثى
المشاركات: 2
افتراضي بليز ساعدوني سؤال في البرمجة


In the game of craps, a pass line bet proceeds as follows: Two six-sided dice are rolled; the first roll of the dice in a craps round is called the " come out roll." A come out roll of 7 or 11 automatically wins, and a come out roll of 2,3 or 12 automatically loses. If 4,5,6,8,9 or 10 is rolled on the come out roll, that number becomes "the point". the player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. if a 7 is rolled first, then the player loses

Write a program that simulates a craps using these rules without human input. Instead of asking for a wager, the program should calculate whether the player would win or lose. the programs should simulate rolling the two dice and calculate the sum. Add a loop so that program plays several times. Add counters that count how many times the player wins, and how many times the player loses. at the end of playing the games several times, computer the probability of wining
( wins/sins+losses)) and output the value

هذا السؤال بليزززز ساعدوني مره حايسة

و هنا الكود الي كتبته ما اعرف اذا صح او لا و فيه غلط

import java.util.Scanner;

public class partb1
{

public static void main(String[] args)
{

int side1=1, side2=1 , roll=1, lose=0, win=0, point=0, answer;
Double winprob, loseprob;

side1= 1+(int)(Math.random() *6);

side2= 1+(int)(Math.random() *6);

Scanner kb = new Scanner(System.in);

do
{
roll = side1+side2;


if ( roll == 7 || roll == 11)
{
System.out.println(" Come out wins");
win = win + 1;

}
else if ( roll ==2 || roll ==3 || roll ==12)
{
System.out.println(" Come out loses ");
lose = lose +1;

}

else
{
side1= 1+(int)(Math.random() *6);
side2= 1+(int)(Math.random() *6);
point = roll;
roll = side1+side2;

System.out.println("The point");
System.out.println("You won the bet");
win = win + 1;
while(roll != point || roll!= 7);
side1= 1+(int)(Math.random() *6);
side2= 1+(int)(Math.random() *6);
roll = side1+side2;

}



if( roll ==7)

{
System.out.println("You lost the bet");
answer = kb.nextInt();
}
else if (roll== point);
System.out.println(win);
}
while(answer);
{
System.out.println(" Do you want to play again? 0 for No, 1 for Yes ");

if (answer ==0)
{
break;
}

winprob = (40/(40+60));
System.out.println(" The probability of wining is " + winprob);

loseprob = (40/(40-60));
System.out.println(" The probability of losing is " + loseprob);




}
}
}

رد مع اقتباس