C++ Ballpark order challenge
Hello im trying to solve the Ballpark Orders challenge in c++ and for some reason, only first item gets right amount when calculation total sum. Here is the code. #include <iostream> #include <sstream> using namespace std; int main() { string burger = "Cheeseburger"; string nachos = "Nachos"; string pizza = "Pizza"; string water = "Water"; string coke = "Coke"; int sum = 0; string order; cin >> order; string arr[4]; int i = 0; stringstream ssin(order); while (ssin.good() && i < 4){ ssin >> arr[i]; ++i; } for (int j = 0; j < 4; j++){ cout << sum; if (arr[j] == nachos || arr[j] == pizza) { sum += 6; } else if (arr[j] == burger ) { sum += 10; } else if (arr[j] == water ){ sum += 4; } else if (arr[j] == coke ){ sum += 5; } else { sum += 5; } } double tax = sum * 0.07; cout << sum + tax; }