0

I want a detailed explanation to code this problem

You and three friends go to a baseball game and you offer to go to the concession stand for everyone. They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. Water is $4.00 and Coke is $5.00. Tax is 7%. Task Determine the total cost of ordering four items from the concession stand. If one of your friend’s orders something that isn't on the menu, you will order a Coke for them instead. Input Format You are given a string of the four items that you've been asked to order that are separated by spaces. Output Format You will output a number of the total cost of the food and drinks. Sample Input 'Pizza Cheeseburger Water Popcorn' Sample Output 26.75

2nd Oct 2024, 1:00 PM
yasminsherif
2 Réponses
0
Thanks for explanation🫡
3rd Oct 2024, 3:54 PM
yasminsherif
+ 1
The approach to a problem like this is to break it down into steps. In this case, you'll first need to parse the input. Then work each input word one at a time in a loop. 1. input from user a. is it valid? b. break it into a list or array 2. Loop through the list a. check each word to get the price b. if not on the list - buy a coke c. accumulate the price - we don't need to keep up with any other details. 3. Add tax 4. Output result By first breaking things down into steps, you get an idea of what you need for your program. 1. Do you need any menus? no 2. Do you need any specific messages or prompts? no 3. Do you need any specific data? YES - you need to know the product list and prices a. You could build that into a data structure like a dictionary, but since only 5 items you could go cheap and just use IF statements b. You also need a SUM variable By spending a few minutes figuring out what the functional steps are and the required data items, you have a lot of your program done. Writing the code is easier by having at least a small plan in place first.
2nd Oct 2024, 1:26 PM
Jerry Hobby
Jerry Hobby - avatar