+ 1

Ballpark Order-Challenge

This code works fine for the first test. But none of the others. I have no idea what could be wrong. #include <iostream> using namespace std; int main() { string answer[4]; string ans0; float sum=0; int x=0; do { cin >>ans0; answer[x]=ans0; if(ans0=="Nachos"||ans0=="Pizza") { sum+=6.00; } if(ans0=="Cheeseburger") { sum+=10.00; } if(ans0=="Water") { sum+=4.00; } else { sum+=5.00; } x++; }while(x<4); sum*=1.07; cout << sum; return 0; }

25th Jan 2022, 2:15 PM
N3stS
4 odpowiedzi
+ 3
You have to use if-else block, last else part tied with if(ans0=="Water") Only... like: if (...) else if(..) else if(...) else ...
25th Jan 2022, 2:25 PM
Jayakrishna 🇮🇳
+ 4
Also, you're missing "Coke" in your solution.
25th Jan 2022, 2:55 PM
Simba
Simba - avatar
+ 2
Simba I decided to skip adding an else if for ’Coke’ specifically. Only reason being because a friend ordering something that’s not on the menu would end up as ’Coke’ anyways.
25th Jan 2022, 3:53 PM
N3stS
+ 1
Jayakrishna🇮🇳 I always forget about those ”else if’s” 🤦🏼‍♂️
25th Jan 2022, 3:51 PM
N3stS