I am supposed to code a program that uses 3 parallel arrays. The program should prompt the user to enter in a Product ID. From there it is supposed to search the ids array and then display the corresponding price and quantity remaining. It does not do this.
Instead I am getting error C2784: 'bool std::operator !=(const std::istream_iterator<_Ty,_Elem,_Traits,... &,const std::istream_iterator<_Ty,_Elem,_Traits,... &)' : could not deduce template argument for 'const std::istream_iterator<_Ty,_Elem,_Traits,... &' from 'int'
1> c:\program files\microsoft visual studio 8\vc\include\iterator(277) : see declaration of 'std::operator !='
I believe that it is because I am using the string searchForId and the array is an integer. I need to be able to search for the array and I don't know how to change the coding or even what to put. I have looked at this for 5 hours and it makes me want to give up on C++. I was finally understanding C++ until arrays.
I am only looking for suggestions, not to have my work done for me.
Thanks for any input anyone can offer.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
//declare arrays
int ids[5] = {10, 14, 34, 45, 78};
int prices[5] = {125, 600, 250, 350, 225};
int quantities[5] = {5, 3, 9, 10, 2};
string searchForId = "";
// get ID to search for
cout << "Enter ID (X to exit): ";
getline(cin, searchForId);
while (searchForId != "X") {
// locate position of prices ID in the ids array
int y = 0; // keeps track of array subscripts
while (y < 5 && ids[y] != searchForId)
y = y + 1;
// end while
// if ID was found then display the price and quantity from the prices/quantity array otherwise display error message
if (y < 5)
cout << "Price for Product ID " << ids[y]
<< ": $" << prices[y] << endl << endl;
cout << "Quantities Remaining: " << ids[y] << endl << prices[y] << endl << quantities[y] << endl << endl;
else
cout << "Invalid Product ID" << endl << endl;
// end if
// get ID to search for
cout << "Enter ID (X to exit): ";
getline(cin, searchForId);
}
// end while
return 0;
} //end of main function