Question
The input file salesin.txt contains a series of lines with three numbers on each line. Each line corresponds to a certain item which have been
The input file salesin.txt contains a series of lines with three numbers on each line. Each line corresponds to a certain item which have been bought and then subsequently sold. The first number is the buying price of the item, the second number is the selling price of the item, and the third number is the quantity sold (integer). We are interested in keeping track of the total profit and total loss over all of the items listed in the file. For example, if a line in the file contains 1.34 1.87 4, then that item yielded a profit of 4(1.87 1.34) = $2.12 and this number should be added to the total profit. Similarly, if another line reads 3.22 2.87 6, then that item had a loss of 6(3.22 2.87) = $2.10 and this number should be added to the total loss.
Write a program, sales.c, which repeatedly reads the buying, selling, and quantity values from salesin.txt and reports the information to an output file salesout.txt along with the item profit and total running profit, or the item loss and total running loss. The program quits when all three quantities entered are zero.
For example, if salesin.txt contains the following lines;
2.56 3.44 8
1.24 1.69 5
8.44 7.32 3
3.67 4.12 8
4.33 4.01 5
0.00 0.00 0
then salesout.txt should contain
2.56 3.44 8: profit = 7.04, total profit = 7.04
1.24 1.69 5: profit = 2.25, total profit = 9.29
8.44 7.32 3: loss = 3.36, total loss = 3.36
3.67 4.12 8: profit = 3.60, total profit = 12.89
4.33 4.01 5: loss = 1.60, total loss = 4.96
PLEASE USE C++ AS A LANGUAGE, THANK YOU SO MUCH!
Step 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