I need to make a program which uses 3 parallel numeric arrays, references each other, then displays the price and quantity of the supplied product id.

It gives me an error message on line 36 about my != searchforID, can anyone enlighten me as to why?

//Ch11AppE12.cpp
//Displays the price and quantity corresponding
//to the item ID entered by the user
//Created/revised by Greg Schader on 7/13/2009

#include <iostream>
#include <string>
#include <algorithm>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::transform;

int main()
{	
	//declare arrays
	string searchforID = "";
	int ids[5]        = {10, 14, 34, 45, 78};
	int prices[5]     = {125, 600, 250, 350, 225};
	int quantities[5] = {5, 3, 9, 10, 2};

	//Enter product ID
	cout << "Enter product ID (X to exit): ";
	getline(cin, searchforID);
        transform (searchforID.begin(), searchforID.end(),
		searchforID.begin(), toupper);
	


	while (searchforID != "X")
	{
		//Find product ID
		int x = 0;
		while (x < 5 && ids[x] != searchforID)
			x = x + 1;

		//If product ID is valid, display price and quantity
		// otherwise, display error message
		if (x<5)
			cout << "Price for product ID " << ids[x] << ": $" << prices[x] << " and quantity is: " << quantities[x] << endl << endl;
		else
			cout << "Invalid product ID" << endl << endl;
		//end if function

		//Enter product ID
	cout << "Enter product ID (X to exit): ";
	getline(cin, searchforID);
	transform (searchforID.begin(), searchforID.end(),
		searchforID.begin(), toupper);
	}  //End of while function




    return 0;
}   //end of main function

main.cpp:36: error: no match for 'operator!=' in 'ids[x] != searchforID'

It's probably curious as to the details of how it should try to compare an int with a string .

I swapped the ids values to strings and it works fine, I just have to have them as int values.

I've read through the entire textbook and none of the examples or text show any way to use a parallel array without the entered value as a string.

'Tis a sad text that doesn't discuss conversion of string input to numeric. I like using stringstreams (example).

Is there anyway to do it without converting string to numeric values? I have to keep them as int values.

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.