[ create a new paste ] login | about

Link: http://codepad.org/JGoOlx6v    [ raw code | output | fork ]

hieunguyenduc696@gmail.com - C++, pasted on Dec 3:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct Product
{
	string ID;
	string Name;
	string Original;
	union
	{
		struct {
			float Price;
			int Number;
		}PRICE;
	} UNION;
};
typedef struct Product PRODUCT;
void fRunSubMenu(PRODUCT [], int , PRODUCT& , string );
int SubMenu();
void Save(ofstream& , PRODUCT );
void SaveList(PRODUCT [], int );
void inProduct(PRODUCT& pr)
{
	cout << "input ID:";
	getline(cin, pr.ID);
	cout << "\ninput Name:";
	getline(cin, pr.Name);
	cout << "\ninput Original:";
	getline(cin, pr.Original);
	cout << "\ninput Price:";
	cin >> pr.UNION.PRICE.Price;
	cout << "\ninput Number:";
	cin >> pr.UNION.PRICE.Number;
	cin.ignore();
}
void inBill(PRODUCT bill[],int &N)
{
	cout << "Input number of bill:";
	cin >> N;
	cin.ignore();
	for (int i = 0; i < N; i++)
	{
		cout << "Input Bill " << i + 1<<endl;
		inProduct(bill[i]);
	}
}
void outProduct(PRODUCT pr)
{
	cout << "ID: " << pr.ID<<endl;
	cout << "Name: " << pr.Name << endl;
	cout << "Original: " << pr.Original << endl;
	cout << "Price: " << pr.UNION.PRICE.Price << endl;
	cout << "Number: " << pr.UNION.PRICE.Number << endl;
	cout << "Pay: " << pr.UNION.PRICE.Number * pr.UNION.PRICE.Price << endl;
}
void outBill(PRODUCT bill[], int N)
{
	for (int i = 0; i < N; i++)
	{	
		cout << "BILL NUMBER " << i + 1 << endl;
		outProduct(bill[i]);
	}
	float sum = 0;
	for (int i = 0; i < N; i++)
	{
		sum += bill[i].UNION.PRICE.Number * bill[i].UNION.PRICE.Price;
	}

	cout << endl;
	cout << "Total money: " << sum << endl;
}
int MainMenu()
{
	cout << "1. Input and Save Bill." << endl;
	cout << "2. Update the bill." << endl;
	cout << "3. Exit." << endl;
	cout << "Select: ";
	return 3;
}
int fSelectMenu(int SelNum)
{
	int command;
	do {
		cin >> command;
		cin.ignore(numeric_limits<streamsize>::max(), '\n');
	} while (command<1 ||command>6);
	return command;
}
void fRunMainMenu(int command,PRODUCT bill[],int &N,PRODUCT& pr,bool &Update)
{
	
	if (command == 1)
	{
		system("cls");
		inBill(bill, N);
		system("cls");
		outBill(bill, N);
		SaveList(bill, N);
		Update = true;
	}
	else if (command == 2)
	{
		if (Update == false)
			cout << "No Bill to update.";
		else
		{
			string FINDID;
			fRunSubMenu(bill, N, pr, FINDID);
		}
	}
	else if (command == 3)
		exit(EXIT_FAILURE);
}
int SubMenu()
{
	system("cls");
	cout << "======UPDATE FUNCTION======";
	cout << "\n1. ID." << endl;
	cout << "2. Name." << endl;
	cout << "3. Original." << endl;
	cout << "4. Price." << endl;
	cout << "5. Number." << endl;
	cout << "6.Exit" << endl;
	cout << "Select: ";
	return 6;
}
void fRunSubMenu(PRODUCT bill[],int N,PRODUCT &pr,string FINDID)
{
	cout << "input ID: ";
	getline(cin, FINDID);
	for (int i = 0; i < N; i++)
	{
		if (bill[i].ID == FINDID)
		{
			int COMMAND = fSelectMenu(SubMenu());
			if (COMMAND == 1)
			{
				system("cls");
				outBill(bill, N);
				cout << "\nInput ID:";
				getline(cin, bill[i].ID);
				outBill(bill, N);
				SaveList(bill, N);
			}
			if (COMMAND == 2)
			{
				system("cls");
				outBill(bill, N);
				cout << "\nInput Name:";
				getline(cin, bill[i].Name);
				outBill(bill, N);
				SaveList(bill, N);
			}
			if (COMMAND == 3)
			{
				system("cls");
				outBill(bill, N);
				cout << "\nInput Original:";
				getline(cin, bill[i].Original);
				outBill(bill, N);
				SaveList(bill, N);
			}
			if (COMMAND == 4)
			{
				system("cls");
				outBill(bill, N);
				cout << "\nInput Price:";
				cin >> bill[i].UNION.PRICE.Price;
				outBill(bill, N);
				SaveList(bill, N);
			}
			if (COMMAND == 5)
			{
				system("cls");
				outBill(bill, N);
				cout << "\nInput Number:";
				cin >> bill[i].UNION.PRICE.Number;
				outBill(bill, N);
				SaveList(bill, N);
			}
			if (COMMAND == 6)
			{
				exit(EXIT_FAILURE);
			}
		}
	}
}
void Save(ofstream &fileout,PRODUCT pr)
{
		fileout << pr.ID<<endl;
		fileout << pr.Name << endl;
		fileout << pr.Original << endl;
		fileout << pr.UNION.PRICE.Price << endl;
		fileout << pr.UNION.PRICE.Number << endl;
		fileout << "Pay for this product: " << pr.UNION.PRICE.Price * pr.UNION.PRICE.Number << endl;
}
void SaveList(PRODUCT bill[], int N)
{
	ofstream fileout;
	fileout.open("LOG.TXT", ios::out);

	for (int i = 0; i < N; i++)
	{
		fileout << "BILL NUMBER: " << i + 1 << endl;
		Save(fileout, bill[i]);
	}	
	float sum = 0;
	for (int i = 0; i < N; i++)
	{
		sum += bill[i].UNION.PRICE.Number * bill[i].UNION.PRICE.Price;
	}
	fileout << "Total money: " << sum << endl;
	
	fileout.close();
}
void main()
{
	int command, N{};
	PRODUCT bill[100], Pr;
	bool Update=false;
	string FindID;
	do
	{
		command = fSelectMenu(MainMenu());
		fRunMainMenu(command, bill, N, Pr, Update);
	} while (command != 3);
}


Output:
1
2
Line 217: error: '::main' must return 'int'
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: