Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

What are some methods of limiting access to interfaces?

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago