Question: The following is the code to play a guessing game. It will keep prompting until the user guesses the correct answer (50). While the user
The following is the code to play a guessing game. It will keep prompting until the user guesses the correct answer (50). While the user is guessing it'll count how many attempts it took the user to guess correctly. When the user correctly guesses the number, it outputs the number of guesses it took.
What is the correct recursive statement that is missing from guess_num() method?
| C# | |
| import java.util.Scanner; class Main { public static int guess_num(int answer,int tries) { Scanner myScan=new Scanner(System.in); System.out.println("Guess a number"); int guess=myScan.nextInt(); if(guess==answer) { System.out.println("Correct"); return tries; } else { //What goes here? } } public static void main(String[] args) { int guesses=guess_num(50,1); System.out.println("It took you "+guesses+" guesses"); } } | using System; class MainClass { public static int guess_num(int answer,int tries) { Console.WriteLine("Guess a number"); string rawguess=Console.ReadLine(); int guess=Int32.Parse(rawguess); if(guess==answer) { Console.WriteLine("Correct"); return tries; } else { //What goes here? } } public static void Main (string[] args) { int guesses=guess_num(50,1); Console.WriteLine("It took you "+guesses+" guesses"); } } |
Question 9 options:
|
| return guess_num(answer+1,tries); |
|
| return guess_num(answer,tries); |
|
| return guess_num(answer,tries-1); |
|
| return guess_num(answer,tries+1); |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
