Hi Coder777,
I am aware the mathematical formula for how to find net profit, however my issue is in the code, can I create a variable "netProfit" and just subtract the two variables revenue and expense, even though they are in a .dat file.
If I can how would the code look like?
Here is the code that I would modify, for example:
With this code my issue is how to create the variable balance which is relevant to each .dat line. I appreciate the help, im sure i am missing something small which is holding me back.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
case 1:
printf( "\nAccounts with zero balances:\n" );
/* read file contents (until eof) */
while ( !feof( cfPtr ) ) {
if ( balance == 0 ) {
printf( "%-10d%-13s%7.2f\n",
account, name, balance );
} /* end if */
/* read account, name and balance from file */
fscanf( cfPtr, "%d%s%lf",
&account, name, &balance );
} /* end while */
|
Also so that everybody is aware, here is the assignment outline:
Create a software solution to the following problem: A simple product application system is needed with the following specifications:
The sequential file (which you have to create) is shown below. Name the data file product.dat It has the following test data:
0001 Irons 200.00 100.00
0002 Curlers 50.00 150.00
0003 Dryers 20.00 60.00
0004 Scissors 900.00 100.00
Product Product
Number Description Revenue Expenses
0001 Irons 200.00 100.00
0002 Curlers 50.00 150.00
0003 Dryers 20.00 60.00
0004 Scissors 900.00 100.00
Write a c program (you also have to create the data file) that will allow the user a number of choices to process and view the information.
The main program should allow the user to enter one of five choices. They are listed below.
Choice 1: Show all of the records in the file, including the Product Number, Product Description, Revenue, Expenses, as well as Net Profit (or Net Loss). The Net Profit (or Net Loss) is calculated by subtracting the Expenses from the Revenue Amount. Additionally show totals (accumulators) for all of the products, including Total Revenue, Total Expenses, and Net Income for each product.
Choice 2: Show all of the records in the file, including the Product Number, Product Description, Revenue, Expenses, as well as Net Profit, in which the Net Profit is greater than 0.00 and less than or equal to 100.00.
Choice 3: Show all of the records in the file, including the Product Number, Product Description, Revenue, Expenses, as well as Net Profit, in which the Net Profit is greater than 500.00 and less than or equal to 1000.00.
Choice 4: Show all of the records in the file, including the Product Number, Product Description, Revenue, Expenses, as well as Net Profit (Net Loss), in which the Net Loss is a less than 0.0.
Choice 5: Show Summary Totals for the Total Revenue, Total Expenses, and Total Net Income for all of the records in the file.
Choice 6: End Program Run
Be sure that your program rewinds the file for each choice made (excluding choice six (ending the program run).
***This is very important:
Right now I am aware that I can only input three variables, this is due to how we practiced it, I wanted to try a simple program before moving on, now all i need to do is add one more user input variable and then calculate net profit, from there the case selection just needs minor modifications