Please help me correcting my program.The question requires me to offer a repeating MENU with 3 choices.
1. Displays all students
2. choose one by entering the ID and also making changes to it.
3.exit.

My error so far is "cannot convert to `int*' for argument `1' to `in".I don't quite understand what's wrong with the linearSearch line,using it for the first time.

#include <iostream>
#include <string>
using namespace std;

int linearSearch(int [],int,int);

struct theStudent
   {          
          string studentName;
          int studentID;
          float studentGPA;
   } ;

string i;


const int arrSize=2;


int main()
{
        
        
        theStudent students[arrSize] = {
                                  {"Robert",7,3.2},
                                  {"Sam",6,3.5}
                                  };
        int location ,id,index,choice,results;
       

do
{ 
    cout <<"MENU"<<endl;
    cout <<"1.View all students"<<endl;
    cout <<"2.Update the list"<< endl;
    cout <<"3.Quit"<< endl;
    cin  >> choice;
    
switch (choice)
{
      case 1:
           cout <<"You have these so far:\n";
           for( index=0;index <2;index++)
           {
             cout<<students[index].studentID<<endl;;
             cout<<students[index].studentName<<endl;
             cout<<students[index].studentGPA<<endl;
             }
           break;
           
      case 2:
      
           cout <<"Enter ID to change info:\n";
           cin >> id;
           results=linearSearch(students,arrSize,id);
           if(results == -1)
           cout<<"Doesn't exist.\n";
           else
           {
           cout<<"That ID is found"<<results;
           cout <<"Make changes" <<endl;
           cin >> students[index].studentID ;//  cin>>students[index].studentID
           cout <<"Make changes to name" << endl;
           cin >>students[index].studentName;
           cout<<"Change the GPA"<<endl;
           cin>>students[index].studentGPA;
           
           }
           } 
      }while(choice!=3);
          
        return 0;   
             }

Your first argument in the search function should be prototyped as theStudent [] instead of int [] (and probably needs to be changed in your function definition as well.

thank you for the reply.
Now I get the following errors.
55 C:\Dev-Cpp\Untitled2.cpp expected primary-expression before '[' token
55 C:\Dev-Cpp\Untitled2.cpp expected primary-expression before ']' token

It probably means you should move your prototype after your struct (probably the best idea) or you can forward declare your struct (put "struct theStudent;" before your prototype and leave the struct declaration in place).

I actually moved it earlier before typing my post.The error remains the same.

Can you post up the search function too so I can give it a try?

#include <iostream>
#include <string>
using namespace std;



struct theStudent
   {          
          string studentName;
          int studentID;
          float studentGPA;
   } ;

string i;

int linearSearch(theStudent[],int,int);
const int arrSize=2;


int main()
{
        
        
        theStudent students[arrSize] = {
                                  {"Robert",7,3.2},
                                  {"Sam",6,3.5}
                                  };
        int location ,id,index,choice,results;
       

do
{ 
    cout <<"MENU"<<endl;
    cout <<"1.View all students"<<endl;
    cout <<"2.Update the list"<< endl;
    cout <<"3.Quit"<< endl;
    cin  >> choice;
    
switch (choice)
{
      case 1:
           cout <<"You have these so far:\n";
           for( index=0;index <2;index++)
           {
             cout<<students[index].studentID<<endl;;
             cout<<students[index].studentName<<endl;
             cout<<students[index].studentGPA<<endl;
             }
           break;
           
      case 2:
      
           cout <<"Enter ID to change info:\n";
           cin >> id;
           results= linearSearch( theStudent[],arrSize,id);
           if(results == -1)
           cout<<"Doesn't exist.\n";
           else
           {
           cout<<"That ID is found"<<results;
           cout <<"Make changes" <<endl;
           cin >> students[index].studentID ;// cin>>students[index].studentID
           cout <<"Make changes to name" << endl;
           cin >>students[index].studentName;
           cout<<"Change the GPA"<<endl;
           cin>>students[index].studentGPA;
           
           }
           } 
      }while(choice!=3);
        return 0; }
      
      int linearSearch(theStudent[],int x,int value)
      {
          int index=0;
      int position =-1;
      bool found=false;
      while(index< x &&!found)
      {
                   if(theStudent[index]==value)
                   {
                                               found =true;
                                               position=index;
                                               }
                                               index++}
                                               return position;}
          
        
             }

Oh ok. I meant to change it in the other two places but not in the function call itself. Take out the brackets on line 55 and just call it with students like you did before.

There's some work to be done in the function definition. You need to come up with a name for your parameter that is of type theStudent and use that in the function instead of just theStudent. You also can't test for equality between a struct and a value.

thank you.

No prob. I had edited my post a couple of times so I didn't know if you got the latest one. It's all good.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.