Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Forgive me for my ignorance, I am just a beginner. So, I am working on a guessing game from 1-1000 using the binary search algorithm

Forgive me for my ignorance, I am just a beginner. So, I am working on a guessing game from 1-1000 using the binary search algorithm and I can't get the program to continue after the user enters their number. Just point me in the right direction and I will do the rest. Thank you very much! :-)

//Guessing Game

#include

using namespace std;

int main()

{

double min, max, mid, number;

cout << "Enter a number between 0 and 1000: " << endl;

cin >> number;

min = 0;

max = 1000;

while(min <= max);

{

mid = ((max - min)/2) + 0.5;

if(number < mid)

max = mid - 1;

else if(number > mid)

min = mid+1;

cout << mid;

}

cout << "Your number is " << mid << " ." << endl;

return 0;

}

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

Students also viewed these Databases questions

Question

Sketch the graph of G(t) = t - [t].

Answered: 1 week ago