2 Replies - 1127 Views - Last Post: 19 October 2011 - 11:08 PM Rate Topic: -----

#1 C++ newb   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 04-September 11

Searching an Array of Struct records - Error?

Posted 19 October 2011 - 09:08 PM

Hello, I'm a beginner in C++ and don't understand what this error message means:

cannot convert `stdRecord*' to `std::string*' for argument `1' to `std::string stdIDComp(std::string*)'


I've tried to create a search function for a student's ID number when a user inputs one to find a match within the array of struct records I already have, but I keep getting this error and I don't know what I've done wrong! Here's my current code:

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

void clrscr()
{
  system("cls");
}

void pause()
{
  system("echo.");system("echo.");system("pause");
}

void displayMenu(string msg)
{
  clrscr();
  cout << msg << "\n\nMAIN MENU\n"
"\n0. Exit"
"\n1. Search for a student"
"\n2. List students enrolled in a course"
"\n3. List students eligible to graduate"
"\n4. List all students"
"\n5. Update a student record"
"\n6. Add a student record"
"\n7. Delete a student record"
"\n\nYour choice is ->";
};
const int MAXRECORD = 500;
struct stdRecord
{
string studentID;
string studentName;
int courseCode;
int creditPoint;
};
const int IDNUM = 8;
string stdIDComp(string [IDNUM]);

int main()
{
  const int NUMRECS = 3;
  
  int option, studentCount, i, j, total = 0;
  string studentIDInput;
  string word, msg="Please type in the number of the corresponding \ntask you wish to perform then press enter.";
  
    stdRecord stdRec[NUMRECS]={{"15000000","Joshua Andrew Smith", 3506, 240},
                               {"16666666", "Jack Williams", 3506, 180},
                               {"17000010", "Lily Jones", 3639, 110}};
  do
  {
    displayMenu(msg);
    cin.clear();
    if(!(cin >> option))
    {
      if(!cin.eof())
      {
        cin.clear();
        cin >> word;
      }
     continue;
    }
   
    switch(option)
    {
    case 1:
        stdIDComp(stdRec) // ****HERE! This is where the error occurs, but I don't know what it means!
        pause ();
        break;
    case 2: // to be filled
    case 3: // to be filled
    case 4: 
        cout << "\nStudent ID  Student Name         Course Code  Credit Points\n\n";
        cout << setiosflags(ios::left);
        for (i = 0; i < MAXRECORD && i < NUMRECS; i++)
       
            cout << setw(12) << stdRec[i].studentID
                 << setw(21) << stdRec[i].studentName
                 << setw(13)  << stdRec[i].courseCode
                 << setw(5)  << stdRec[i].creditPoint << endl;             
        pause ();
        break;
    case 5: // to be filled
    case 6: // to be filled
    case 7: // to be filled
    default:
      cout << "No options from choices one to seven have been typed.";
      pause ();
      break;
    }
    
  } while (option!=0);
  return 0;
}

string stdIDComp(string searchRec[NUMRECS][MAXRECORD]) // this is my function to be used in case 1
{
    int i;
    for(int i = 0; i < MAXRECORD && i < NUMRECS; i++)
    {
        if(strcmp(stdRec[i].studentID, stdIDInput)==0) 
        {
            cout << i << endl;
            break;
        }
    }
}



Could someone point me in the right direction???

Is This A Good Question/Topic? 0
  • +

Replies To: Searching an Array of Struct records - Error?

#2 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2408
  • View blog
  • Posts: 4,542
  • Joined: 30-May 10

Re: Searching an Array of Struct records - Error?

Posted 19 October 2011 - 10:35 PM

Well you basically need to make your mind up.

string stdIDComp(string [IDNUM]);
Here, it's an array of string.

stdIDComp(stdRec) // ****HERE! This is where the error occurs, but I don't know what it means!
Here, it's an array of stdRecord

string stdIDComp(string searchRec[NUMRECS][MAXRECORD]) // this is my function to be used in case 1
And here, it's a 2D array of string


Just make the function declaration/definition match what you're trying to pass in, like so.

string stdIDComp(stdRecord stdRec[NUMRECS]);
...
string stdIDComp(stdRecord stdRec[NUMRECS]) // this is my function to be used in case 1


Was This Post Helpful? 0
  • +
  • -

#3 C++ newb   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 04-September 11

Re: Searching an Array of Struct records - Error?

Posted 19 October 2011 - 11:08 PM

Ah! Thank you so much, I get it now! I was kind of confused because I was trying to understand other examples I found in the textbook, but now it seems so simple! Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1