int user(int x);
int computer(int x);
int binarySearch( int &search, int x, int i, int The_Number);
int computer(int x)
{
int The_Number = x;
int fool = 0;
int Address;
constint SIZE(100);
int search[SIZE];
int lastnumber = 100, Guess, firstnumber = 0;
for (int i = 0; i < 100; i++)
{
Address = i + 1;
search[i] = Address;
}
while (x != Guess)
{
binarySearch(search, firstnumber, lastnumber, The_Number);
}
cout << "Computer Guessed the Right Number!" << endl;
return fool;
}
// x fist i last number
int binarySearch(constint &search, int x, int i, int The_Number)
{
bool found = false;
int first = x, last = i;
int mid;
while (first <= last && !found)
{
mid = (first + last) / 2;
if (The_Number < search[mid])
}
}
int binarySearch(constint &search, int x, int i, int The_Number)
should be int binarySearch(constint search[], int x, int i, int The_Number)
Be sure to make this change in your function declaration at the top of the program, I notice that const is not in your declaration but is in the definition down below.
You don't even need & in this case as you can't have an array of references.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
usingnamespace std;
// It int x does not have to match with main function but int function have to match
// Function for user or computer
int user(int z);
int computer(int z);
int binarySearch(constint& search, int& x, int& i, int The_Number);
int main()
{
srand(unsigned(time(NULL)));
bool quit = true;
int Player, Computer, Guess, choice;
constint x = 100;
do{
// Make Number I want to Guess
Guess = rand() % x + 1;
cout << Guess << endl;
cout << "Enter 1 to Play as Player or 2 to see Computer Play or 3 to quit" << endl;
cin >> choice;
// Make Sure User press one or two
if (choice == 1)
{
Player = user(Guess);
}
elseif (choice == 2)
{
Computer = computer(Guess);
}
} while (quit);
return 0;
}
int user(int z)
{//function for Player!!!!
int number = 0, i = 0;
while (z != number)
{
cout << "Enter int number (guess number)!" << endl;
cin >> number;
// Enters if Number is Higher than Guess Number!
if (z < number)
{
cout << "Your Number is Higher!" << endl;
}
//Enters if Number is Lower than Guess Number!
elseif (z > number)
{
cout << "Your Number is Lower!" << endl;
}
}
cout << "Congraduation You Got the Guess the Right Number!"<< endl;
return i;
}
int computer(int z)
{
int The_Number = z;
int fool = 0;
int Address;
constint SIZE = 100;
int search[SIZE];
int lastnumber = 100, Guess, firstnumber = 0;
for (int i = 0; i < 100; i++)
{
Address = i + 1;
search[i] = Address;
}
while (z != Guess)
{
binarySearch(search[SIZE], firstnumber, lastnumber, The_Number);
}
cout << "Computer Guessed the Right Number!" << endl;
return fool;
}
// x fist i last number
int binarySearch(constint& search, int& x, int& i, int The_Number)
{
bool found = false;
int mid = 0;
while (x <= i && !found)
{
mid = (x + i) / 2;
if (The_Number < search[mid])
{
}
}
}
this is what i have right now have underline on search[mid]
@wh1t3crayon but you can have a reference to array (this'd work only for static arrays), if I remember correctly. Still here it's better to use a pointer to array.
Oh, you didn't make the change which I provided for you. Line 83, change int& search to int search[]. You do want search to be an array, right?
Now that leaves line 77, where you are passing an int equal to the size of search[], not the search array itself. I believe you just want to pass the array? If so, just remove [SIZE] from line 77.
Side note, be sure to initialize Guess in line 68, and make sure that binarySearch() returns an int value.
@TheHardew right but in the parameters passing a reference of an int array (like the OP was trying to do anyways) would not compile.
No no, you're just on a learning curve. My first post ever was asking how to call a function from a class object (I am not joking, that took me days to understand).