// Pixel to em calulator
// Date 00:58 13/12/2016
// By Ben a.k.a DreamVB

#include <Windows.h>
#include <iostream>

using namespace std;
using std::cout;
using std::endl;

void ColorFont(WORD color){
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, color);
}

void Caption(){
	//Set caption font color
	ColorFont(31);
	//Set caption text
	cout << "--- Pixel to em calulator ---\n\n";
	//Restore font color.
	ColorFont(15);
}

int main(int argc, char *argv[]){
	double pixel = 0.0;
	double em = 0.0;
	double result = 0.0;
	char c = '\0';

	bool running = true;

	while (running){
		Caption();
		cout << "Enter parent pixel size : ";
		cin >> pixel;
		cout << "Enter required pixel size : ";
		cin >> em;

		//Show em
		result = (em / pixel);
		cout << "\nTotal: " << result << "em\n\n";

		//Ask to convert agian.
		cout << "Convert agian (Y/N) : ";
		cin >> c;
		c = toupper(c);

		//Check what user has entered.
		if (c == 'N'){
			cout << "\nThanks for trying the program.\n";
			running = false;
			break;
		}
		//Error invaild choice exit.
		if(c != 'Y'){
			cout << "\nInvaild choice program will now exit.\n";
			break;
		}
		//Yes was entered clear screen and start again.
		if (c == 'Y'){
			system("cls");
		}
	}

	system("pause");
	return EXIT_SUCCESS;
}