C++ Arrays and nested if..

I couldn't get the forum to work...

I can't figure out what's wrong with this block of code, I don't see any errors. The program runs but skips this whole block for some reason, obviously theres more code than this such as my declarations, arrays, and outputs. This seems to be the issue though, any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
 if(choice != -1) 
	{
    	if ((choice >= 1) and (choice <= 5))
		{
    		totalPrice = totalPrice + prices[choice - 1];
    		cout << "Item number ", choice, ": ", products[choice - 1], "has been added.";
		}
    	else
    		cout << "Item number ", choice, " is not valid", "Sorry we do not carry that item";
	}

	totalPrice = totalPrice + COFFEEPRICE;


something to add, I have these two arrays, and int SIZE = 5;
1
2
 const string products[SIZE] = {"Whipped Cream", "Cinnamon", "Chocolate Sauce", "Amaretto", "Irish Whisky"};
	const int prices[SIZE] = {0.89, 0.25, 0.59, 1.50, 1.75};
Last edited on
and is a syntax error. In C++, you need to use &&. Line 3.

cout << "Item number ", choice, ": ", products[choice - 1], "has been added.";

Again, syntax error. Instead of , , you need to use <<

Something like...
cout << "Item number " << choice << ": ", products[choice - 1], "has been added."; You can figure out the rest of it.
Last edited on
Thanks for the reply, I had actually just changed that before you commented, but when I type 6 for example it should throw the error in the else, but it doesn't.
Never mind, I believe I got it. Thank you.
Topic archived. No new replies allowed.