I was having an error, it says cannot convert string into int..i have no idea how to convert string into int. My teacher asked me to read 5 students names into the array..help me pls..
#include<iostream>
#include<string>
#include <stdlib.h>
using namespace std;
int search(int data[], int size, int value)
{
int lower, middle, upper;
lower = 0;
upper = size-1;
while(true)
{
middle = (lower + upper)/2;
if (data[middle] == value)
return middle;
else if (lower >= upper)
return -1;
else if (data[middle] > value)
upper = middle -1;
else
lower = middle +1;
}
}
void main()
{
string name[5];
for (int i=0;i<5;i++)
{
cin >> name[i];
}
int index;
int input;
cout << "\n\nSearch = ";
cin >> input;
index = search(name,5,input);
if (index == -1)
cout << "Not Found "<<endl;
else
cout << "Found at " << index <<endl;
}