Arrays in a loop question
Allow me to enter 2 different C++ codes before I ask the question // 1ST CODE #include <iostream> using namespace std; int main() { double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; //your code goes here float discount; float discounted; cin >> discount; for (int x = 0; x < 11; x++) { discounted = items[x] - (items[x] * discount) / 100; cout << discounted << " "; } return 0; } // 2ND CODE #include <iostream> using namespace std; int main() { double items[] = {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; //your code goes here float discount; float discounted; cin >> discount; for (int x = 0; x < 11; x++) { discounted = (items[x] * discount) / 100; cout << discounted << " "; } return 0; } As you can see, at the bottom of the code. There is a difference. One subtracts items[x] and the other doesn't. Why is that? The first one is correct but why?