Question: Please help with my following code. It does not create a file at all, instead the stuff that I wanted it to print out in
Please help with my following code. It does not create a file at all, instead the stuff that I wanted it to print out in the displaySalesData function is only displayed in the usually output section when code is run but i want a text file to be created for the infomration to be stored there, please help. i used a little bit of infomration in the buy cars function so that the infromation worked out can be aended to the file, please help me to fix this. Here is the code:
These are the genral imports i have used in my code #include this is for input and output functions
#include this is for the string operation strcpy
#include this is required for bool data type
#include this is for opening and closing files
#include
if giveDiscount
printfDiscount was given
;
printfYour discount value is: f
carPricescarIndex DISCOUNTPERCENTAGE;
else
printfDiscount was not given
;
printfTotal Price: f
totalPrice;
Update the car stock
The carStock array is a global variable so it can be constantly updated
carStockcarIndex carsNeeded;
printf
The remaining stock for s: d
carModelscarIndex carStockcarIndex;
track the total sale statistics
the number of sales per transaction
totalSales;
the number of cars sold
totalCarsSold carsNeeded;
the total price of the cars sold
totalProfit totalPrice;
total customers sold to
totalCustomers;
writes the sales data to the file, this is connected to view car sales data function
FILE file fopencarSalestxta;
if file NULL
printfError: Could not open sales data file.
;
return;
writes the sale data which is car model, units sold, price per unit to the csv file
fprintffilesdf
carModelscarIndex carsNeeded, carPricescarIndex;
fclosefile;
numberOfSalesMade;
void displayCarSalesData
printfThis is the current car stock ;
displayCarStock;
FILE file fopencarSalestxtr;
if file NULL
printfError: Could not open sales data file.
;
char data;
whilefgetsdata sizeofdata file
printfThis is all the previous sales made ;
printfModel and Profit s
data;
printfHere is your sales summary!
;
printfThe total number of sales is d
totalSales;
printfThe total number of cars sold is: d therefore the total profit is f GBP
totalCarsSold, totalProfit;
printfThe number of customers served is: d
totalCustomers;
printfThe total price of discounts given is: f
totalDiscounts;
fclosefile;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
