Question: I need help converting the following Java code to C language? package dicegame; import java.util.Random; import java.util.Scanner; public class DiceGame { static int moneyInBank; public

I need help converting the following Java code to C language?

package dicegame; import java.util.Random; import java.util.Scanner; public class DiceGame { static int moneyInBank; public static void main(String[] args) { System.out.println("Let's play CHUCK-A-LUCK!"); Scanner scanner = new Scanner(System.in); System.out.print("Enter money to bank: $"); moneyInBank = scanner.nextInt(); scanner.nextLine(); System.out.println("+----------------------------------------------------------------------------+"); String option; String playAgain; do { System.out.print("How much would you like to bet? $"); int betMoney = scanner.nextInt(); //flush scanner.nextLine(); System.out.print("What bet would you like to place (N-numbers, F-field, O-odd, E-even, H-high, L-low): "); option = scanner.nextLine(); //Use a switch statement to determine which option has been entered by the user switch (option) { case "N": case "n": System.out.print("Select the number (1-6): "); int numSelected = scanner.nextInt(); scanner.nextLine(); int firstN = generateRandom()[0]; int secondN = generateRandom()[1]; int thirdN = generateRandom()[2]; System.out.print("**" + firstN + "**\t**" + secondN + "**\t**" + thirdN + "** "); if (numSelected == firstN && numSelected == secondN && numSelected == thirdN) { int moneyWon = betMoney * 10; moneyInBank += moneyWon; System.out.println("YOU WIN $" + moneyWon + "!! You have $" + moneyInBank + " in your bank."); } else if (numSelected == firstN && numSelected == secondN && numSelected != thirdN || numSelected == firstN && numSelected != secondN && numSelected == thirdN || numSelected != firstN && numSelected == secondN && numSelected == thirdN) { int moneyWon = betMoney * 2; moneyInBank += moneyWon; System.out.println("YOU WIN $" + moneyWon + "!! You have $" + moneyInBank + " in your bank."); } else if (numSelected == firstN || numSelected == secondN || numSelected == thirdN) { moneyInBank += betMoney; System.out.println("YOU WIN $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } break; case "F": case "f": firstN = generateRandom()[0]; secondN = generateRandom()[1]; thirdN = generateRandom()[2]; System.out.print("**" + firstN + "**\t**" + secondN + "**\t**" + thirdN + "** "); int total = firstN + secondN + thirdN; if (total == 5 || total == 6 || total == 7 || total == 8 || total == 13 || total == 14 || total == 15 || total == 16) { moneyInBank += betMoney; System.out.println("YOU WIN $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } break; case "O": case "o": firstN = generateRandom()[0]; secondN = generateRandom()[1]; thirdN = generateRandom()[2]; System.out.print("**" + firstN + "**\t**" + secondN + "**\t**" + thirdN + "** "); total = firstN + secondN + thirdN; if (total % 2 != 0) { moneyInBank += betMoney; System.out.println("YOU WIN $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } else if (firstN == secondN && firstN == thirdN) { moneyInBank -= betMoney; System.out.println("YOU LOSE $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } break; case "E": case "e": firstN = generateRandom()[0]; secondN = generateRandom()[1]; thirdN = generateRandom()[2]; System.out.print("**" + firstN + "**\t**" + secondN + "**\t**" + thirdN + "** "); total = firstN + secondN + thirdN; if (total % 2 == 0) { moneyInBank += betMoney; System.out.println("YOU WIN $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } else if (firstN == secondN && firstN == thirdN) { moneyInBank -= betMoney; System.out.println("YOU LOSE $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } break; case "H": case "h": firstN = generateRandom()[0]; secondN = generateRandom()[1]; thirdN = generateRandom()[2]; System.out.print("**" + firstN + "**\t**" + secondN + "**\t**" + thirdN + "** "); total = firstN + secondN + thirdN; if (total > 10) { moneyInBank += betMoney; System.out.println("YOU WIN $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } else if (firstN == secondN && firstN == thirdN) { moneyInBank -= betMoney; System.out.println("YOU LOSE $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } break; case "L": case "l": firstN = generateRandom()[0]; secondN = generateRandom()[1]; thirdN = generateRandom()[2]; System.out.print("**" + firstN + "**\t**" + secondN + "**\t**" + thirdN + "** "); total = firstN + secondN + thirdN; if (total < 11) { moneyInBank += betMoney; System.out.println("YOU WIN $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } else if (firstN == secondN && firstN == thirdN) { moneyInBank -= betMoney; System.out.println("YOU LOSE $" + betMoney + "!! You have $" + moneyInBank + " in your bank."); } break; default: System.out.println("Invalid option"); } if (moneyInBank == 0) break; else { System.out.print("Do you want to play again (Y/N)? "); playAgain = scanner.nextLine(); } } while (!playAgain.equalsIgnoreCase("n") && moneyInBank != 0); if (moneyInBank == 0) { System.out.println(" You have $" + moneyInBank + " in your bank."); System.out.println("Game Over."); } else { System.out.println(" You cashed out $" + moneyInBank + "."); System.out.println("Game Over."); } } static void menu() { System.out.println( "What bet would you like to place ()" ); } static int[] generateRandom() { Random random = new Random(System.currentTimeMillis()); int first = random.nextInt(10 - 1 + 1) + 1; int second = random.nextInt(10 - 1 + 1) + 1; int third = random.nextInt(10 - 1 + 1) + 1; int[] numbers = {first, second, third}; return numbers; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!