0

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.

thermoplay
  • 75
  • 8
  • Hint: https://en.wikipedia.org/wiki/Windows-1252 – Mooing Duck Feb 26 '20 at 01:05
  • formatting by tabs will break your output when the numbers are long. Why don't just use [the built-in formatting options of `cout`](https://stackoverflow.com/q/35393334/995714) or [`printf`](https://stackoverflow.com/q/9206669/995714)??? Numbers are also typically right-aligned instead of left like that – phuclv Feb 26 '20 at 06:42
  • the main issue is just printing Unicode characters which is tricky on older Windows [Output unicode strings in Windows console app](https://stackoverflow.com/q/2492077/995714), [Unicode output on Windows command line?](https://stackoverflow.com/q/1035388/995714), [How to use unicode characters in Windows command line?](https://stackoverflow.com/q/388490/995714), [CMD: How to use non-English characters?](https://superuser.com/q/625866/241386). Things are a lot better on Windows 10 – phuclv Feb 26 '20 at 06:49

0 Answers0