+ 2

(Solved) Ballpark Orders (cpp)

I am trying to learn cpp as my first language (difficult I know). I am having a bit of trouble with how to solve the Code Coach Example "Ballpark Orders". If anyone can help me out or give me any hints as to a different way of going at this--that would be much appreciated! Here is the link to my personal copy-paste version. I couldn't get it to my computer sorry: https://code.sololearn.com/cl30c1mXqOe8/#cpp

1st Apr 2022, 3:02 PM
Jimmy Scholz
10 odpowiedzi
0
By using loop, you can do in less lines and more readable form.. Anyways, check the spell in "Nachos", is it "Nacho" only?
1st Apr 2022, 3:46 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 oh my god thank you so much!!! I forgot to correct that after reading your post! Thank you once again!!!
5th Apr 2022, 12:54 PM
Jimmy Scholz
+ 1
G'day Jimmy Scholz nice code! I've found when I copy+paste the expected input/output from the challenge text into my comments then I don't get typos. As Jaya' said, use a loop. I would: Start loop, take one input, process it, add to the total, loop again. Tax at the end is best, that reduces rounding errors. Also, you don't need to specifically check for "Coke" because the first 4 checks tear off any the values that result in not $5. Just use your catch all line else *ptr += 5; If your question is solved, don't forget to edit your original Q&A post title to start with [Solved]
1st Apr 2022, 9:15 PM
HungryTradie
HungryTradie - avatar
+ 1
Hi HungryTradie! Thank you so much for your insight! I did what you suggested and it is now updated in the code. The issue is, in that same code prompt, case 4 is always incorrect. All of the other ones are correct. Has anyone else either had this issue or, even better, have solved this?
3rd Apr 2022, 6:04 PM
Jimmy Scholz
+ 1
Where is your update code ?
3rd Apr 2022, 6:14 PM
Jayakrishna 🇮🇳
+ 1
Jimmy Scholz you did not read posts clearly.. Spelling of "Nachos" Missing s in your code. I mentioned in first post.. Thats only problem with your code from start I think. Hope it helps..
4th Apr 2022, 5:46 PM
Jayakrishna 🇮🇳
0
That's great Jimmy. I think others also have had trouble with rounding or precision of decimals. I've not found Cpp examples of that, but Jayakrishna🇮🇳 is pretty good at that kind of thing! Maybe using the older printf() instead of cout? printf("%.2f",total); //this will always print only 2 digits after the decimal point
3rd Apr 2022, 8:10 PM
HungryTradie
HungryTradie - avatar
0
Hey here is my updated code: https://code.sololearn.com/cl30c1mXqOe8/?ref=app The only thing is, this is in the Code Coach as “Ballpark Orders”. I want to try and solve this in C++ if possible, but i have been at this code and “Case 4” is always incorrect. I cannot seem to get it right. Can someone help me out with “Case 4” specifically?
4th Apr 2022, 5:01 PM
Jimmy Scholz
0
HungryTradie and Jayakrishna🇮🇳 thank you guys so much for your inputs. I have i corperated both of your ideas into my code. But can I have help with the Code Coach names “Ballpark Orders” please? Thank youa again!!!
4th Apr 2022, 5:02 PM
Jimmy Scholz
0
You're welcome..
5th Apr 2022, 1:04 PM
Jayakrishna 🇮🇳