"cannot convert 'std::string' to 'int' for argument '1' to 'int linearSearch(int, int*, int)'".
Basically my main arrays consists of:
string studentID[] = {"P1001", P"1002"}
int studentMark[] = {78.50, 66}
I am trying to allow the user to search for a given studentID, and the output will display the correponding marks for it. I am trying to use linear search (not sure if Im doing it right or not)
My coding looks like this at the moment:
#include <iostream>
#include <string>
using namespace std;
int linearSearch(int, int [], int);
int main()
{
int menu;
string studentID[] = {"P1001", "P1002"};
float studentMark[] = {78.50, 66};
int totalStudents=0;
float totalMarks=0;
float averageMark;
string id;
int mark;
char studentGrade;
int j;
int i=linearSearch(id,studentMark,2);
cout << "MAIN MENU\n"
<< "0. Exit 1. Statistics\n"
<< "2. Enter mark 3. Find mark\n"
<< "------------------------------\n"
<< "Your choice -> ";
cin >> menu;
while (menu != 0)
{
switch (menu)
{
case 1:
for(int j=0;j<2;j++)
{
totalMarks+=studentMark[j];
totalStudents++;
}
averageMark=totalMarks/totalStudents;
cout << "Number of records: " << totalStudents <<endl;
cout << "Mean or average: " << averageMark <<endl;
break;
case 2:
cout << "Enter a Student Record: " <<endl;
cout << "Student ID -> ";
cin >> id;
break;
case 3:
cout << "Find marks for ID -> " << endl;
cin >> id;
else
cout << "Student Record does not exist";
break;
default:
cout << "Invalid selection. Please make a selection between 0-3.\n"
<< endl;
break;
}
system("Pause");
cout << "MAIN MENU\n"
<< "0. Exit 1. Statistics\n"
<< "2. Enter mark 3. Find mark\n"
<< "----------------------------\n"
<< "Your choice -> ";
cin >> menu;
}
return 0;
}
How can I fix the error?

New Topic/Question
Reply




MultiQuote






|