C++ Polygon Namer

Musicrafter 24 Mar 2015 00:41

I made a polygon naming algorithm that can print out the full Greek name of any polygon from a 1-gon to a 99,999-gon. Note that it is pretty useless because most of the time we'd just call a 24,742-gon that rather than a dimyriatetrachiliaheptohectotetracontakaidigon. I'm pretty sure I got them right, but then again, I extrapolated most of the prefixes.

Warning: Long code ahead.

```
#include<iostream>
#include<string>
using namespace std;
signed long int input()
{
signed long int integer;
cout<<"How many sides does the polygon have? ";
cin>>integer;
return integer;
}
void checksplit(signed long int & n1, signed long int & n2, signed long int & n3, signed long int & n4, signed long int & n5)
{
signed long int number, numeral;
numeral = input();
number = numeral;
n1 = number % 10;
number /= 10;
n2 = number % 10;
number /= 10;
n3 = number % 10;
number /= 10;
n4 = number % 10;
number /= 10;
n5 = number % 10;
number /= 10;
if (numeral > 99999 || numeral < 1)
{
n1 = 0;
n2 = 0;
n3 = 0;
n4 = 0;
n5 = 0;
cout<<"Error. This program can only calculate numbers between 1 and 99999.\n"<<endl;
}
}
int main()
{
for(;;)
{
signed long int m1, m2, m3, m4, m5, array[5];
int firsttime;
string ones, tens, kai, hundreds, thousands, tenthousands;
if (firsttime == 0)
cout<<"This program will name any polygon based on the number of sides.\n"<<endl;
checksplit(m1, m2, m3, m4, m5);
array[4] = m1;
array[3] = m2;
array[2] = m3;
array[1] = m4;
array[0] = m5;
if (array[4] == 1)
{
if (array[3] == 1)
ones = "hen";
else
ones = "hena";
if (array[3] == 0 && array[2] == 0 && array[1] == 0 && array[0] == 0)
ones = "mono";
}
if (array[4] == 2)
{
if (array[3] == 1)
ones = "do";
else
ones = "di";
}
if (array[4] == 3)
{
if (array[3] == 1)
ones = "tris";
else
ones = "tri";
}
if (array[4] == 4)
ones = "tetra";
if (array[4] == 5)
ones = "penta";
if (array[4] == 6)
ones = "hexa";
if (array[4] == 7)
ones = "hepta";
if (array[4] == 8)
ones = "octa";
if (array[4] == 9)
{
if (array[3] == 0 && array[2] == 0 && array[1] == 0 && array[0] == 0)
ones = "nona";
else
ones = "ennea";
}
if (array[4] == 0)
ones = "";
if (array[3] == 1)
tens = "deca";
if (array[3] == 2)
{
if (array[4] == 0)
tens = "icosa";
else
tens = "icosi";
}
if (array[3] == 3)
tens = "triaconta";
if (array[3] == 4)
tens = "tetraconta";
if (array[3] == 5)
tens = "pentaconta";
if (array[3] == 6)
tens = "hexaconta";
if (array[3] == 7)
tens = "septaconta";
if (array[3] == 8)
tens = "octaconta";
if (array[3] == 9)
tens = "enneaconta";
if (array[3] == 0)
tens = "";
if (array[2] == 1)
hundreds = "hecto";
if (array[2] == 2)
hundreds = "dihecto";
if (array[2] == 3)
hundreds = "trihecto";
if (array[2] == 4)
hundreds = "tetrahecto";
if (array[2] == 5)
hundreds = "pentahecto";
if (array[2] == 6)
hundreds = "hexahecto";
if (array[2] == 7)
hundreds = "heptahecto";
if (array[2] == 8)
hundreds = "octahecto";
if (array[2] == 9)
hundreds = "enneahecto";
if (array[2] == 0)
hundreds = "";
if (array[1] == 1)
thousands = "chilia";
if (array[1] == 2)
thousands = "dichilia";
if (array[1] == 3)
thousands = "trichilia";
if (array[1] == 4)
thousands = "tetrachilia";
if (array[1] == 5)
thousands = "pentachilia";
if (array[1] == 6)
thousands = "hexachilia";
if (array[1] == 7)
thousands = "heptachilia";
if (array[1] == 8)
thousands = "octachilia";
if (array[1] == 9)
thousands = "enneachilia";
if (array[1] == 0)
thousands = "";
if (array[0] == 1)
tenthousands = "myria";
if (array[0] == 2)
tenthousands = "dimyria";
if (array[0] == 3)
tenthousands = "trimyria";
if (array[0] == 4)
tenthousands = "tetramyria";
if (array[0] == 5)
tenthousands = "pentamyria";
if (array[0] == 6)
tenthousands = "hexamyria";
if (array[0] == 7)
tenthousands = "heptamyria";
if (array[0] == 8)
tenthousands = "octamyria";
if (array[0] == 9)
tenthousands = "enniamyria";
if (array[0] == 0)
tenthousands = "";
if (array[4] != 0 && ((array[3] >= 1 && array[4] >= 3) || array[3] >= 2))
kai = "kai";
else
kai = "";
if (array[4] > 2 && array[4] < 5 && array[3] == 0 && array[2] == 0 && array[1] == 0 && array[0] == 0)
{
if (array[4] == 3)
cout<<"triangle / trigon\n"<<endl;
if (array[4] == 4)
cout<<"quadrilateral / tetragon\n"<<endl;
}
else if (array[0] + array[1] + array[2] + array[3] + array[4] != 0)
{
cout<<tenthousands<<thousands<<hundreds;
if (array[3] == 1)
cout<<ones<<kai<<tens<<"gon\n"<<endl;
else
cout<<tens<<kai<<ones<<"gon\n"<<endl;
}
system("pause");
firsttime = 1;
cout<<"\n";
}
}
```