| blaxroze (2) | ||||||
|
Here's my problem, I cant seem to display the output. For the output we were supposed to display Item name and the Profit for each corresponding item. This is my sales.txt it is arranged in this form "item, cost, sale price, number of sales".
Here is my code
This is the output I get
| ||||||
|
Last edited on
|
||||||
| elfico (14) | |
|
from what i see, the in the function "display", you are writing your data to your file only. to display the data, first read the data and then try to display. try put this code: void CalcProfits(ifstream &dataSales, string &Item, double &Cost ,double &SalePrice, double &Profit, double &TotalProfit, double &SalesNumber) { TotalProfit=0; while (dataSales >> Item >> Cost >> SalePrice >> SalesNumber) { Profit=(SalePrice-Cost)*SalesNumber; outdataSales << Item << Cost << SalePrice << SalesNumber<<Profit TotalProfit+=Profit; dataSales.close(); } } and also void display(ifstream &dataSales,ofstream &outdataSales, string &Item, double &Cost ,double &SalePrice, double &Profit, double &TotalProfit, double &SalesNumber) { cout <<"REPORT SALES PC SHOP SDN BHD"<<endl; cout <<"__________________________________________"<<endl; cout <<" ITEM"<<setw(35)<<"PROFIT"<<endl; cout <<"__________________________________________"<<endl; while (dataSales << Item << Cost << SalePrice << SalesNumber) { cout << Item << setw(20) << Profit; } cout <<"__________________________________________"<<endl; cout << "TOTAL PROFIT" <<setw(25) << TotalProfit<<endl; } | |
|
|
|
| blaxroze (2) | |
|
I tried your code, but it seems like the last code got an error. If I do it your way, I wont get my "TotalProfit". You see, in your "void CalcProfit" if I close the file in "while" I will never get "TotalProfit". edit: I think I have to save each of my profit value into an array, but I dont really know how to do it. Any hint? | |
|
Last edited on
|
|