Hi, I'm looking for a program that uses parallel one-dimensional arrays so when a user inputs the product ID, they have displayed the quantity and the price.
Here is my code so far:
My problem isCode:#include <iostream> using std::cout; using std::cin; using std::endl; using std::string; using std::transform; int main() { //declare arrays string searchId = " "; int ids[5] = {10, 14, 34, 45, 78}; int prices[5] = {125, 600, 250, 350, 225}; int quantities[5] = {5, 3, 9, 10, 2}; //get id to search for, then convert to uppercase cout << "Enter ID (X to exit): "; getline (cin, searchId); transform (searchId.begin(), searchId.end(), searchId.begin(), toupper); while (searchId != "X") { //locate position of product ID in the ids array int y = 0; //keeps track of array subcripts while (y < 5 && ids[y] != searchId) y += 1; //end while //if ID was found, display price from prices array if (y < 5) cout << "Price for product ID: " << ids[y] << ": $" << prices[y] << endl << endl; //then display quantity from the quantities arry cout << "Quantit for product ID: " << ids[y] << ": " << quantities[y] << endl << endl; //If ID not found, display error message else cout << "Invalid product ID" << endl << endl; //end if //get ID to search for, then convert to uppercase cout << "Enter ID (X to exit): "; getline (cin, searchId); transform (searchId.begin(), searchId.end(), searchId.begin(), toupper); } //end while return 0; } //end of main function
is getting a no match for 'operator!+' in 'ids[y]!=searchId'Code:while (y < 5 && ids[y] != searchId)
My second problem is
is getting an expected primary-expression before "else". I do have a (Code:elseat the end of the line above else..
If anyone can help me, or point me in the right direction, that would be awesome. Ive only been coding for about a month.
Thanks again



LinkBack URL
About LinkBacks
at the end of the line above else..



