Checking Array problem

I have an array with size 10. I allow the user to enter in a product code and if the product code matches one in the array it will tell them the price of that product. On the other hand, if the product code is not found I want it to tell them the product was not found. Im' not sure what the problem is. Here is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
for(int sub=0; sub < SIZE; sub++)
    {
		if(userCode == codes[sub])
		{
			price = prices[sub];
			cout << "The price for Product Code " << userCode << " is: " << price;
		}else if (userCode != codes[sub] && (sub+1) == SIZE)
		{
			cout << "Product code not found";
			break;
		}
		
    }


Thanks in advance
Last edited on
What are the types of your variables and arrays?
int userCode, codes[];
double price, prices[];
Last edited on
Got it. Added a break after the cout if the statement is true.
Topic archived. No new replies allowed.