I'm making a store system here in my local place using ifstream and a textfile at that,I would like to use the (Philipine)peso sign but it cannot be recognized and only displays '?'. Here's my code
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main() {
ifstream productlist;
string filename;
cout << "Enter File Name: ";
cin >> filename;
productlist.open(filename);
if (!productlist.is_open()) {
cout << "File failed to open \n";
return 0;
}
double netprofit ,sumcapital = 0, sumsp = 0, sumitems = 0, sumpautangitems = 0, sumvaluecash = 0, sumtotalpautang = 0, sumtotalpuhunan = 0;
string name, squantity, sprice,scapitalprice,numberofpautang;
double quantity, price, capitalprice, pautang, totalpuhunan, totalprofit;
string line;
double totalcash = 0;
cout << "Product Name\t|" << "Capital Price\t|" << "Price\t|" << "Quantity\t |"<< "# of Pautang\t|"<< "Total Cash\t|" << "Pautang\t|" << "Total Capital\t|" << "Total Profit\n";
while (getline(productlist, line)) {
stringstream ss(line);
getline(ss, name, '/');
getline(ss, scapitalprice, '/');
capitalprice = stod(scapitalprice);
getline(ss, sprice, '/');
price = stod(sprice);
getline(ss, squantity, '/');
quantity = stod(squantity);
getline(ss, numberofpautang);
pautang = stod(numberofpautang);
double valuecash = quantity * price;
totalcash = totalcash + valuecash;
double pautangincome = pautang * price;
totalpuhunan = (quantity + pautang) * capitalprice;
double totalprice;
totalprice = (quantity + pautang) * price;
sumcapital = sumcapital + capitalprice;
sumsp = sumsp + price;
sumitems = sumitems + quantity;
sumpautangitems = pautang + sumpautangitems;
sumvaluecash = sumvaluecash + valuecash;
sumtotalpautang = sumtotalpautang + totalpuhunan;
sumtotalpuhunan = sumtotalpuhunan + totalprice;
netprofit = sumtotalpuhunan - sumtotalpautang;
if (name.length() > 8) {
cout << name << "\t|₱" << capitalprice << "\t\t|₱" << price << "\t|" << quantity << "\t\t |" << pautang << "\t\t|₱" << valuecash << "\t\t|₱" << pautangincome << "\t\t|₱" << totalpuhunan << "\t\t|₱" << totalprice << endl;
}
else if (name.length() > 16) {
cout << name << "|₱" << capitalprice << "\t\t|₱" << price << "\t|" << quantity << "\t\t |" << pautang << "\t\t|₱" << valuecash << "\t\t|₱" << pautangincome << "\t\t|₱" << totalpuhunan << "\t\t|₱" << totalprice << endl;
}
else {
cout << name << "\t\t|₱" << capitalprice << "\t\t|₱" << price << "\t|" << quantity << "\t\t |" << pautang << "\t\t|₱" << valuecash << "\t\t|₱" << pautangincome << "\t\t|₱" << totalpuhunan << "\t\t|₱" << totalprice << endl;
}
}
cout << "\nToday's Sales:\t|₱" << sumcapital << "\t\t|₱" << sumsp << "\t|" << sumitems << "\t\t |" << sumpautangitems << "\t\t|₱" << sumvaluecash << "\t\t|" << sumpautangitems << "\t\t|₱" << sumtotalpautang << "\t\t|₱" << sumtotalpuhunan << endl;
cout << "NET PROFIT : ₱" << netprofit;
productlist.close();
}
Here's the text file:
mighty/3.45/5/4/0
shampoosunsilk/4.50/6/1/0
and here's the output during runtime :
Product Name |Capital Price |Price |Quantity |# of Pautang |Total Cash |Pautang |Total Capital |Total Profit
mighty |?3.45 |?5 |4 |0 |?20 |?0 |?13.8 |?20
shampoosunsilk |?4.5 |?6 |1 |0 |?6 |?0 |?4.5 |?6
Today's Sales: |?7.95 |?11 |5 |0 |?26 |0 |?18.3 |?26
NET PROFIT : ?7.7
The dollar sign works, but I preferably like our local currency to be the displayed currency sign.