Question
Write a program named Groceries that accepts input file items.txt the user. The data in the input file represents grocery items purchased along with their
Write a program named Groceries that accepts input file items.txt the user. The data in the input file represents grocery items purchased along with their price and their discount category. Your program should compute and print a double representing the total cost of the grocery items. Each item is represented by three tokens starting with the name of the item followed by its discount category ("red", "blue" or "none") followed by its full price. The discount category may include capitalization. The different discount options are: red: 10% off full price blue: 25% off full price none: full price For example, if the input file items.txt has the following text:
The program should print 9.59. Explanation: The avocado will cost $0.9 because a discount of 10% off of $1 is $0.1. Blueberries cost the full price of $5. Milk will cost $1.50 because it receives a discount of 25% off of $2.00. Cream will cost $0.9 and cereal will cost the full price of $1.29. The total is 0.9 + 5 + 1.5 + .9 + 1.29 = 9.59. Notice that the input may span multiple lines and may have different spacing between tokens. The entire file represents a single grocery bill. You may assume that the input file exists and has the format described above. The file will always contain at least one grocery item and will always contain a number of tokens that is a multiple of 3. The second token in every triple will always be one of "red", "blue" or "none".
avocado RED 1 blueberries none 5 milk blue 2.00 cream red 1.00 cereal None 1.29Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started