Help with my searching my array

This is a discussion on Help with my searching my array within the C++ Programming forums, part of the General Programming Boards category; Hi i am trying to create a programme that will let me enter car details in to an array and ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    14

    Help with my searching my array

    Hi i am trying to create a programme that will let me enter car details in to an array and then let me search them after and bring up all the details but im having problems with one of the lines to do with the search. Here is the section of code that seems to be the problem (i have wrote more but am trying to reframe to put the whole code online)

    Code:
    int search(Car autos[], int size, int search_id)
    {
    	bool found=false;
    	int i;
    	 for (i=0; i<size; i++)
    	{
    		if (search_id == autos[i].carreg) { found = true; break;}
    	}
    	if (found)
    		return i;
    	else
    		return -1; //not found

    and specifically this exact line
    if (search_id == autos[i].carreg) { found = true; break;}

    error c2784 comes up 9 times

    greatful for any help

    IAN

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Please, show how you determine the class Car

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,657
    Quote Originally Posted by snooki View Post

    error c2784 comes up 9 times
    That doesn't mean anything. What is the full text of the error? Since it came up nine times, is there an error earlier than this line?

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Wouldn't you like this better?

    Code:
    int search(Car autos[], int size, int search_id)
    {
    	for (int i=0; i<size; i++)
    	{
    		if (search_id == autos[i].carreg) { return i; }
    	}
    	return -1; //not found
    }

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    14
    the car comes from here
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    struct Car
    {
    string carmake;
    string carreg;
    string carmodel;
    int carmile;
    };

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So why are you trying to compare an int with a string?

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    14
    i dont understand what you mean? i populate the arrays called carmake, carreg, carmodel and carmile. and then wanna search any details i have entered via the carreg.

    do u mean because search_id is an int, and carreg is a string

  8. #8
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Well...YEAH!? Is an integer a string???

  9. #9
    Registered User
    Join Date
    Dec 2009
    Posts
    14
    ok ok i get you know, i cahnged the search_id to a string that part is working now. thankyou very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By bennywhere in forum C Programming
    Replies: 16
    Last Post: 10-20-2009, 09:00 PM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. searching thru a c++ class array
    By stanleyw in forum C++ Programming
    Replies: 1
    Last Post: 05-29-2002, 09:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21