CODE
//Author:
//File: HexCalculator.cpp
/*
--Purpose--
×Create a hexidecimal calculator that can:
1. Perform the mathematical operation addition
2. Perform the mathematical operation subtraction
3. Perform the mathematical operation multiplication
4. Perform the mathematical operation division
5. Convert a hexadecimal number to it's decimal equivalent
6. Convert a decimal number to it's hexadecimal equivalent
*/
//enum for operations
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
enum MenuType {ADD, SUBTRACT, MULTIPLY, DIVIDE, HEX_TO_DECIMAL, DECIMAL_TO_HEX, QUIT};
//function prototype
MenuType GetMenuPick();
string GetHex();
void Add();
void Subtract();
void Multiply();
void Divide();
int ConvertFromDecimal(string);
string ConvertFromHex(int);
void InvalidHex();
void OperationSelector(MenuType);
int main()
{
MenuType choice;
choice = GetMenuPick();
OperationSelector(choice);
}
MenuType GetMenuPick()
{
char choice;
cout << "HEXIDECIMAL CALCULATOR\n\n\n\n";
cout << "Please Select one of the following options\n"
<< "A for addition\n"
<< "S for subtraction\n"
<< "M for multiplication\n"
<< "D for division\n"
<< "C to convert a hexidecimal number to its decimal equivalent\n"
<< "H to convert a decimal number to its hexidecimal equivalent\n"
<< "Q to exit the program\n";
cin >> choice;
choice = toupper(choice);
switch(choice)
{
case 'A':
{
system("cls");
return ADD;
break;
}
case 'S':
{
system("cls");
return SUBTRACT;
break;
}
case 'M':
{
system("cls");
return MULTIPLY;
break;
}
case 'D':
{
system("cls");
return DIVIDE;
break;
}
case 'C':
{
system("cls");
return HEX_TO_DECIMAL;
break;
}
case 'H':
{
system("cls");
return DECIMAL_TO_HEX;
break;
}
case 'Q':
{
return QUIT;
break;
}
default:
{
cout << "Im sorry, the option you selected is invalid.\n"
<< "Please try again.\n";
system("pause");
system("cls");
GetMenuPick();
break;
}
}
}
void OperationSelector(/*in*/ MenuType choice)
{
while(choice != 'Q')
{
switch(choice)
{
case ADD:
{
cout << "adddition" << endl;
system("pause");
system("cls");
choice = GetMenuPick();
break;
}
case SUBTRACT:
{
cout << "subtract" << endl;
system("pause");
system("cls");
choice = GetMenuPick();
break;
}
case MULTIPLY:
{
cout << "subtract" << endl;
system("pause");
system("cls");
choice = GetMenuPick();
break;
}
case DIVIDE:
{
cout << "subtract" << endl;
system("pause");
system("cls");
choice = GetMenuPick();
break;
}
case HEX_TO_DECIMAL:
{
cout << "subtract" << endl;
system("pause");
system("cls");
choice = GetMenuPick();
break;
}
case DECIMAL_TO_HEX:
{
cout << "subtract" << endl;
system("pause");
system("cls");
choice = GetMenuPick();
break;
}
}
}
}
void Add()
{
int decimalhex1;
int decimalhex2;
int intsum;
string stringhex1;
string stringhex2;
string stringsum;
stringhex1 = GetHex();
stringhex2 = GetHex();
decimalhex1 = ConvertFromHex(stringhex1);
decimalhex2 = ConvertFromHex(stringhex2);
intsum = decimalhex1 + decimalhex2;
stringsum = ConvertFromDecimal(intsum);
cout << stringhex1 << " + " << stringhex2 << " = " << stringsum << endl;
}
string GetHex()
{
string hexnum;
cout << "Enter a hexadecimal number: " << endl;
cin >> hexnum;
return hexnum;
}
int ConvertFromHex(/*in*/ string hex1)
{
}
string ConvertFromDecimal(/*in*/ int num)
{
}
void Subtract();
void Multiply();
void Divide();
void ToDecimal();
void ToHex();
edit: added [code] tags ~ jayman9