Advertisement
Guest User

Roman Numeral Calculator c++

a guest
Mar 1st, 2016
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cctype>
  5. #include <windows.h>                // ZeroMemory
  6. #include <boost/multiprecision/cpp_int.hpp> // uint1024_t
  7.  
  8. using namespace boost::multiprecision;
  9. using namespace std;
  10.  
  11.  
  12. int1024_t int1024_sqrt(int1024_t x)
  13. {
  14.     register int1024_t op, res, one;
  15.    
  16.     op = x;
  17.     res = 0;
  18.    
  19.     /* "one" starts at the highest power of four <= than the argument. */
  20.     one = 1 << 30;  /* second-to-top bit set */
  21.     while (one > op) one >>= 2;
  22.    
  23.     while (one != 0) {
  24.         if (op >= res + one)
  25.         {
  26.             op -= res + one;
  27.             res += one << 1;  // <-- faster than 2 * one
  28.         }  
  29.         res >>= 1;
  30.         one >>= 2;
  31.     }
  32.  
  33.     return res;
  34. }
  35.  
  36. int value(char roman)
  37. {
  38.     switch(roman)
  39.     {
  40.         case 'I':return 1;
  41.         case 'V':return 5;
  42.         case 'X':return 10;
  43.         case 'L':return 50;
  44.         case 'C':return 100;
  45.         case 'D':return 500;
  46.         case 'M':return 1000;
  47.         case 'i':return 1;
  48.         case 'v':return 5;
  49.         case 'x':return 10;
  50.         case 'l':return 50;
  51.         case 'c':return 100;
  52.         case 'd':return 500;
  53.         case 'm':return 1000;
  54.        
  55.         default: return 0;  //if roman is not a roman numeral
  56.     }
  57. }
  58.  
  59. int1024_t from_roman(const string& input)
  60. {
  61.     int1024_t sum=0;
  62.     char prev='%';
  63.     for(int i=(input.length()-1); i>=0; i--)
  64.     {
  65.         if(value(input[i])<sum && (input[i]!=prev)) {
  66.             sum -= value(input[i]);
  67.             prev = input[i];
  68.         } else {
  69.             sum += value(input[i]);
  70.             prev = input[i];
  71.         }
  72.     }
  73.     return sum;
  74. }
  75.  
  76.  
  77. std::string to_roman(int1024_t value)
  78. {
  79.     struct romandata_t { int value; char const* numeral; };
  80.     static romandata_t const romandata[] = {
  81.         1000, "M",
  82.         900, "CM",
  83.         500, "D",
  84.         400, "CD",
  85.         100, "C",
  86.          90, "XC",
  87.          50, "L",
  88.          40, "XL",
  89.          10, "X",
  90.           9, "IX",
  91.           5, "V",
  92.           4, "IV",
  93.           1, "I",
  94.           0, NULL }; // end marker
  95.     std::string result;
  96.     for (romandata_t const* current = romandata; current->value > 0; ++current)
  97.     {
  98.         while (value >= current->value)
  99.         {
  100.             result += current->numeral;
  101.             value  -= current->value;
  102.         }
  103.     }
  104.   return result;
  105. }
  106.  
  107.  
  108.  
  109. int main( void ) {
  110.     char input[520];    //520 because (sizeof(sub1) + sizeof(sub2) + 2 potential signs + 2 potential operator characters + 1 null character (to end the string)) * 2 (for potential spaces)
  111.     char sub1[128];     //128 because it is the size (in bytes) of int1024_t
  112.     char sub2[128];
  113.     unsigned short cur1;
  114.     unsigned short cur2;
  115.     bool sign1;
  116.     bool sign2;
  117.     unsigned short num1;
  118.     unsigned short num2;
  119.     int1024_t numeral1;
  120.     int1024_t numeral2;
  121.     unsigned short i;
  122.     while (true)
  123.     {
  124.         ZeroMemory(&input, sizeof(input));
  125.         ZeroMemory(&sub1, sizeof(sub1));
  126.         ZeroMemory(&sub2, sizeof(sub2));
  127.         num1=0;
  128.         num2=0;
  129.         numeral1 = 0;
  130.         numeral2 = 0;
  131.         i=0;
  132.         cout << "\nCalculate: ";
  133.         gets(input);
  134.         if (feof(stdin)!=0) {   //checks if an error has occured
  135.             cout << "An error has occured: You have somehow entered an invalid (end-of-file) character.";
  136.             return 0;
  137.         }
  138.        
  139.        
  140.        
  141.         i = 0;
  142.         while (value(input[i])==0)
  143.         {
  144.             ++i;
  145.         }
  146.         sign1 = (input[i-1]=='-');
  147.        
  148.         for ( cur1 = sign1; ( (num1!=sizeof(sub1))&&(input[cur1]!='+')&&(input[cur1]!='-')&&(input[cur1]!='*')&&(input[cur1]!='/')&&(input[cur1]!='|')&&(input[cur1]!='>')&&
  149.                     (input[cur1]!='^')&&(input[cur1]!='%')&&(input[cur1]!='&')&&(input[cur1]!='!')&&(input[cur1]!='~')&&(input[cur1]!='<')&&(input[cur1]!='=')&&
  150.                     (input[cur1]!='.')  ); ++cur1 )
  151.         {
  152.             if (value(input[cur1])!=0)      //makes the non-roman characters (such as spaces) be skipped
  153.             {
  154.                 sub1[num1] = (char)toupper(input[cur1]);
  155.                 ++num1;
  156.             }
  157.         }
  158.        
  159.         i = cur1;
  160.         while (value(input[i])==0)
  161.         {
  162.             ++i;
  163.         }
  164.         sign2 = (input[i-1]=='-');
  165.        
  166.        
  167.        
  168.         if (num1!=sizeof(sub1))
  169.         {
  170.             goto operator_exists;
  171.         } else {
  172.             cout << "An error has occured: You must put a valid operator between the two roman numerals.";
  173.             goto end_of_while_statement;
  174.         }
  175.        
  176.        
  177.        
  178.         operator_exists:
  179.         for (cur2 = sign2; ( (num2!=sizeof(sub2)) && (input[cur2+cur1+1]!=0) ); ++cur2 )
  180.         {
  181.             if (value(input[cur2+cur1+1])!=0)
  182.             {
  183.                 sub2[num2] = (char)toupper(input[cur2+cur1+1]);
  184.                 ++num2;
  185.             }
  186.         }
  187.         numeral1 = ( from_roman(sub1) * (sign1?-1:1) );
  188.         numeral2 = ( from_roman(sub2) * (sign1?-1:1) );
  189.         switch((int)input[cur1])
  190.         {
  191.             case '+': {
  192.                     switch (input[cur1+1])
  193.                     {
  194.                         case '+':{
  195.                                 cout << to_roman(numeral1+(++numeral2));
  196.                                 goto end_of_while_statement;
  197.                              }
  198.                         case '~':{
  199.                                 cout << to_roman(numeral1+(~numeral2));
  200.                                 goto end_of_while_statement;
  201.                              }
  202.                         case '!':{
  203.                                 cout << to_roman(numeral1+(!numeral2));
  204.                                 goto end_of_while_statement;
  205.                              }
  206.                         case '=':{
  207.                                 cout <<to_roman( (input[cur1+2]=='>') ? ((++numeral1)>=numeral2) : ((input[cur1+2]=='<')?((++numeral1)<=numeral2):((++numeral1)==numeral2)) );
  208.                                 goto end_of_while_statement;
  209.                              }
  210.                         case '>':{
  211.                                 cout << to_roman( (input[cur1+2]=='=') ? ((++numeral1)>=numeral2) : ((++numeral1)>numeral2) );
  212.                                 goto end_of_while_statement;
  213.                              }
  214.                         case '<':{
  215.                                 cout << to_roman( (input[cur1+2]=='=') ? ((++numeral1)<=numeral2) : ((++numeral1)<numeral2) );
  216.                                 goto end_of_while_statement;
  217.                              }
  218.                         case '/':{
  219.                                 cout << to_roman((++numeral1)/numeral2);
  220.                                 goto end_of_while_statement;
  221.                              }
  222.                         case '*':{
  223.                                 cout << to_roman((++numeral1)*numeral2);
  224.                                 goto end_of_while_statement;
  225.                              }
  226.                         case '^':{
  227.                                 cout << to_roman((++numeral1)^numeral2);
  228.                                 goto end_of_while_statement;
  229.                              }
  230.                         case '%':{
  231.                                 cout << to_roman((++numeral1)%numeral2);
  232.                                 goto end_of_while_statement;
  233.                              }
  234.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  235.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  236.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  237.                                 strcpy( cat_chars, to_roman(++numeral1).c_str() );
  238.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  239.                                 cout << cat_chars;
  240.                                 goto end_of_while_statement;
  241.                              }
  242.                         default: {
  243.                                 cout << to_roman(numeral1+numeral2);
  244.                                 goto end_of_while_statement;
  245.                              }
  246.                     }
  247.                   }
  248.             case '-': {
  249.                     switch (input[cur1+1])
  250.                     {
  251.                         case '+':{
  252.                                 cout << to_roman(numeral1-(++numeral2));
  253.                                 goto end_of_while_statement;
  254.                              }
  255.                         case '~':{
  256.                                 cout << to_roman(numeral1-(~numeral2));
  257.                                 goto end_of_while_statement;
  258.                              }
  259.                         case '!':{
  260.                                 cout << to_roman(numeral1-(!numeral2));
  261.                                 goto end_of_while_statement;
  262.                              }
  263.                         case '=':{
  264.                                 cout <<to_roman( (input[cur1+2]=='>') ? ((--numeral1)>=numeral2) : ((input[cur1+2]=='<')?((--numeral1)<=numeral2):((--numeral1)==numeral2)) );
  265.                                 goto end_of_while_statement;
  266.                              }
  267.                         case '>':{
  268.                                 cout << to_roman( (input[cur1+2]=='=') ? ((--numeral1)>=numeral2) : ((--numeral1)>numeral2) );
  269.                                 goto end_of_while_statement;
  270.                              }
  271.                         case '<':{
  272.                                 cout << to_roman( (input[cur1+2]=='=') ? ((--numeral1)<=numeral2) : ((--numeral1)<numeral2) );
  273.                                 goto end_of_while_statement;
  274.                              }
  275.                         case '/':{
  276.                                 cout << to_roman((--numeral1)/numeral2);
  277.                                 goto end_of_while_statement;
  278.                              }
  279.                         case '*':{
  280.                                 cout << to_roman((--numeral1)*numeral2);
  281.                                 goto end_of_while_statement;
  282.                              }
  283.                         case '^':{
  284.                                 cout << to_roman((--numeral1)^numeral2);
  285.                                 goto end_of_while_statement;
  286.                              }
  287.                         case '%':{
  288.                                 cout << to_roman((--numeral1)%numeral2);
  289.                                 goto end_of_while_statement;
  290.                              }
  291.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  292.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  293.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  294.                                 strcpy( cat_chars, to_roman(--numeral1).c_str() );
  295.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  296.                                 cout << cat_chars;
  297.                                 goto end_of_while_statement;
  298.                              }
  299.                         default: {
  300.                                 cout << to_roman(numeral1-numeral2);
  301.                                 goto end_of_while_statement;
  302.                              }
  303.                     }
  304.                   }
  305.             case '/': {
  306.                     switch (input[cur1+1])
  307.                     {
  308.                         case '+':{
  309.                                 cout << to_roman(numeral1/(++numeral2));
  310.                                 goto end_of_while_statement;
  311.                              }
  312.                         case '~':{
  313.                                 cout << to_roman(numeral1/(~numeral2));
  314.                                 goto end_of_while_statement;
  315.                              }
  316.                         case '!':{
  317.                                 cout << to_roman(numeral1/(!numeral2));
  318.                                 goto end_of_while_statement;
  319.                              }
  320.                         case '=':{
  321.                                 cout <<to_roman( (input[cur1+2]=='>') ? (int1024_sqrt(numeral1)>=numeral2) : ((input[cur1+2]=='<')?(int1024_sqrt(numeral1)<=numeral2):(int1024_sqrt(numeral1)==numeral2)) );
  322.                                 goto end_of_while_statement;
  323.                              }
  324.                         case '>':{
  325.                                 cout << to_roman( (input[cur1+2]=='=') ? (int1024_sqrt(numeral1)>=numeral2) : (int1024_sqrt(numeral1)>numeral2) );
  326.                                 goto end_of_while_statement;
  327.                              }
  328.                         case '<':{
  329.                                 cout << to_roman( (input[cur1+2]=='=') ? (int1024_sqrt(numeral1)<=numeral2) : (int1024_sqrt(numeral1)<numeral2) );
  330.                                 goto end_of_while_statement;
  331.                              }
  332.                         case '/':{
  333.                                 cout << to_roman(int1024_sqrt(numeral1)/numeral2);
  334.                                 goto end_of_while_statement;
  335.                              }
  336.                         case '*':{
  337.                                 cout << to_roman(int1024_sqrt(numeral1)*numeral2);
  338.                                 goto end_of_while_statement;
  339.                              }
  340.                         case '^':{
  341.                                 cout << to_roman(int1024_sqrt(numeral1)^numeral2);
  342.                                 goto end_of_while_statement;
  343.                              }
  344.                         case '%':{
  345.                                 cout << to_roman(int1024_sqrt(numeral1)%numeral2);
  346.                                 goto end_of_while_statement;
  347.                              }
  348.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  349.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  350.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  351.                                 strcpy( cat_chars, to_roman(int1024_sqrt(numeral1)).c_str() );
  352.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  353.                                 cout << cat_chars;
  354.                                 goto end_of_while_statement;
  355.                              }
  356.                         default: {
  357.                                 cout << to_roman(numeral1/numeral2);
  358.                                 goto end_of_while_statement;
  359.                              }
  360.                     }
  361.                   }
  362.             case '*': {
  363.                     switch (input[cur1+1])
  364.                     {
  365.                         case '+':{
  366.                                 cout << to_roman(numeral1*(++numeral2));
  367.                                 goto end_of_while_statement;
  368.                              }
  369.                         case '~':{
  370.                                 cout << to_roman(numeral1*(~numeral2));
  371.                                 goto end_of_while_statement;
  372.                              }
  373.                         case '!':{
  374.                                 cout << to_roman(numeral1*(!numeral2));
  375.                                 goto end_of_while_statement;
  376.                              }
  377.                         case '=':{
  378.                                 cout <<to_roman( (input[cur1+2]=='>') ? ((numeral1*numeral1)>=numeral2) : ((input[cur1+2]=='<')?((numeral1*numeral1)<=numeral2):((numeral1*numeral1)==numeral2)) );
  379.                                 goto end_of_while_statement;
  380.                              }
  381.                         case '>':{
  382.                                 cout << to_roman( (input[cur1+2]=='=') ? ((numeral1*numeral1)>=numeral2) : ((numeral1*numeral1)>numeral2) );
  383.                                 goto end_of_while_statement;
  384.                              }
  385.                         case '<':{
  386.                                 cout << to_roman( (input[cur1+2]=='=') ? ((numeral1*numeral1)<=numeral2) : ((numeral1*numeral1)<numeral2) );
  387.                                 goto end_of_while_statement;
  388.                              }
  389.                         case '/':{
  390.                                 cout << to_roman((numeral1*numeral1)/numeral2);
  391.                                 goto end_of_while_statement;
  392.                              }
  393.                         case '*':{
  394.                                 cout << to_roman((numeral1*numeral1)*numeral2);
  395.                                 goto end_of_while_statement;
  396.                              }
  397.                         case '^':{
  398.                                 cout << to_roman((numeral1*numeral1)^numeral2);
  399.                                 goto end_of_while_statement;
  400.                              }
  401.                         case '%':{
  402.                                 cout << to_roman((numeral1*numeral1)%numeral2);
  403.                                 goto end_of_while_statement;
  404.                              }
  405.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  406.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  407.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  408.                                 strcpy( cat_chars, to_roman(numeral1*numeral1).c_str() );
  409.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  410.                                 cout << cat_chars;
  411.                                 goto end_of_while_statement;
  412.                              }
  413.                         default: {
  414.                                 cout << to_roman(numeral1*numeral2);
  415.                                 goto end_of_while_statement;
  416.                              }
  417.                     }
  418.                   }
  419.             case '^': {
  420.                     switch (input[cur1+1])
  421.                     {
  422.                         case '+':{
  423.                                 cout << to_roman(numeral1^(++numeral2));
  424.                                 goto end_of_while_statement;
  425.                              }
  426.                         case '~':{
  427.                                 cout << to_roman(numeral1^(~numeral2));
  428.                                 goto end_of_while_statement;
  429.                              }
  430.                         case '!':{
  431.                                 cout << to_roman(numeral1^(!numeral2));
  432.                                 goto end_of_while_statement;
  433.                              }
  434.                         case '=':{
  435.                                 cout <<to_roman( (input[cur1+2]=='>') ? ((numeral1^(numeral1<<1))>=numeral2) : ((input[cur1+2]=='<')?((numeral1^(numeral1<<1))<=numeral2):((numeral1^(numeral1<<1))==numeral2)) );
  436.                                 goto end_of_while_statement;
  437.                              }
  438.                         case '>':{
  439.                                 cout << to_roman( (input[cur1+2]=='=') ? ((numeral1^(numeral1<<1))>=numeral2) : ((numeral1^(numeral1<<1))>numeral2) );
  440.                                 goto end_of_while_statement;
  441.                              }
  442.                         case '<':{
  443.                                 cout << to_roman( (input[cur1+2]=='=') ? ((numeral1^(numeral1<<1))<=numeral2) : ((numeral1^(numeral1<<1))<numeral2) );
  444.                                 goto end_of_while_statement;
  445.                              }
  446.                         case '/':{
  447.                                 cout << to_roman((numeral1^(numeral1<<1))/numeral2);
  448.                                 goto end_of_while_statement;
  449.                              }
  450.                         case '*':{
  451.                                 cout << to_roman((numeral1^(numeral1<<1))*numeral2);
  452.                                 goto end_of_while_statement;
  453.                              }
  454.                         case '^':{
  455.                                 cout << to_roman((numeral1^(numeral1<<1))^numeral2);
  456.                                 goto end_of_while_statement;
  457.                              }
  458.                         case '%':{
  459.                                 cout << to_roman((numeral1^(numeral1<<1))%numeral2);
  460.                                 goto end_of_while_statement;
  461.                              }
  462.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  463.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  464.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  465.                                 strcpy( cat_chars, to_roman(numeral1*numeral1).c_str() );
  466.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  467.                                 cout << cat_chars;
  468.                                 goto end_of_while_statement;
  469.                              }
  470.                         default: {
  471.                                 cout << to_roman(numeral1^numeral2);
  472.                                 goto end_of_while_statement;
  473.                              }
  474.                     }
  475.                   }
  476.             case '%': {
  477.                     switch (input[cur1+1])
  478.                     {
  479.                         case '+':{
  480.                                 cout << to_roman(numeral1%(++numeral2));
  481.                                 goto end_of_while_statement;
  482.                              }
  483.                         case '~':{
  484.                                 cout << to_roman(numeral1%(~numeral2));
  485.                                 goto end_of_while_statement;
  486.                              }
  487.                         case '!':{
  488.                                 cout << to_roman(numeral1%(!numeral2));
  489.                                 goto end_of_while_statement;
  490.                              }
  491.                         case '=':{
  492.                                 cout <<to_roman( (input[cur1+2]=='>') ? ((numeral1%numeral2)>=numeral2) : ((input[cur1+2]=='<')?((numeral1%numeral2)<=numeral2):((numeral1%numeral2)==numeral2)) );
  493.                                 goto end_of_while_statement;
  494.                              }
  495.                         case '>':{
  496.                                 cout << to_roman( (input[cur1+2]=='=') ? ((numeral1%numeral2)>=numeral2) : ((numeral1%numeral2)>numeral2) );
  497.                                 goto end_of_while_statement;
  498.                              }
  499.                         case '<':{
  500.                                 cout << to_roman( (input[cur1+2]=='=') ? ((numeral1%numeral2)<=numeral2) : ((numeral1%numeral2)<numeral2) );
  501.                                 goto end_of_while_statement;
  502.                              }
  503.                         case '/':{
  504.                                 cout << to_roman((numeral1%numeral2)/numeral2);
  505.                                 goto end_of_while_statement;
  506.                              }
  507.                         case '*':{
  508.                                 cout << to_roman((numeral1%numeral2)*numeral2);
  509.                                 goto end_of_while_statement;
  510.                              }
  511.                         case '^':{
  512.                                 cout << to_roman((numeral1%numeral2)^numeral2);
  513.                                 goto end_of_while_statement;
  514.                              }
  515.                         case '%':{
  516.                                 cout << to_roman((numeral1%numeral2)%numeral2);
  517.                                 goto end_of_while_statement;
  518.                              }
  519.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  520.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  521.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  522.                                 strcpy( cat_chars, to_roman(numeral1%numeral2).c_str() );
  523.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  524.                                 cout << cat_chars;
  525.                                 goto end_of_while_statement;
  526.                              }
  527.                         default: {
  528.                                 cout << to_roman(numeral1%numeral2);
  529.                                 goto end_of_while_statement;
  530.                              }
  531.                     }
  532.                   }
  533.             case '.': {
  534.                     char cat_chars[sizeof(sub1)+sizeof(sub2)];
  535.                     ZeroMemory(&cat_chars, sizeof(cat_chars));
  536.                     strcpy( cat_chars, to_roman(numeral1).c_str() );
  537.                     strcat( cat_chars, to_roman(numeral2).c_str() );
  538.                     cout << cat_chars;
  539.                     goto end_of_while_statement;
  540.                   }
  541.             case '&': {
  542.                     switch (input[cur1+1])
  543.                     {
  544.                         case '+':{
  545.                                 cout << to_roman(numeral1&(++numeral2));
  546.                                 goto end_of_while_statement;
  547.                              }
  548.                         case '~':{
  549.                                 cout << to_roman(numeral1&(~numeral2));
  550.                                 goto end_of_while_statement;
  551.                              }
  552.                         case '!':{
  553.                                 cout << to_roman(numeral1&(!numeral2));
  554.                                 goto end_of_while_statement;
  555.                              }
  556.                         case '/':{
  557.                                 cout << to_roman((numeral1&numeral2)/numeral2);
  558.                                 goto end_of_while_statement;
  559.                              }
  560.                         case '*':{
  561.                                 cout << to_roman((numeral1&numeral2)*numeral2);
  562.                                 goto end_of_while_statement;
  563.                              }
  564.                         case '^':{
  565.                                 cout << to_roman((numeral1&numeral2)^numeral2);
  566.                                 goto end_of_while_statement;
  567.                              }
  568.                         case '%':{
  569.                                 cout << to_roman((numeral1&numeral2)%numeral2);
  570.                                 goto end_of_while_statement;
  571.                              }
  572.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  573.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  574.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  575.                                 strcpy( cat_chars, to_roman(numeral1&numeral2).c_str() );
  576.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  577.                                 cout << cat_chars;
  578.                                 goto end_of_while_statement;
  579.                              }
  580.                         default: {
  581.                                 cout << to_roman(numeral1&numeral2);
  582.                                 goto end_of_while_statement;
  583.                              }
  584.                     }
  585.                   }
  586.             case '|': {
  587.                     switch (input[cur1+1])
  588.                     {
  589.                         case '+':{
  590.                                 cout << to_roman(numeral1|(++numeral2));
  591.                                 goto end_of_while_statement;
  592.                              }
  593.                         case '~':{
  594.                                 cout << to_roman(numeral1|(~numeral2));
  595.                                 goto end_of_while_statement;
  596.                              }
  597.                         case '!':{
  598.                                 cout << to_roman(numeral1|(!numeral2));
  599.                                 goto end_of_while_statement;
  600.                              }
  601.                         case '/':{
  602.                                 cout << to_roman((numeral1|numeral2)/numeral2);
  603.                                 goto end_of_while_statement;
  604.                              }
  605.                         case '*':{
  606.                                 cout << to_roman((numeral1|numeral2)*numeral2);
  607.                                 goto end_of_while_statement;
  608.                              }
  609.                         case '^':{
  610.                                 cout << to_roman((numeral1|numeral2)^numeral2);
  611.                                 goto end_of_while_statement;
  612.                              }
  613.                         case '%':{
  614.                                 cout << to_roman((numeral1|numeral2)%numeral2);
  615.                                 goto end_of_while_statement;
  616.                              }
  617.                         case '.':{  //in this calculator, the '.' symbol is the concatinatination operator
  618.                                 char cat_chars[sizeof(sub1)+sizeof(sub2)];
  619.                                 ZeroMemory(&cat_chars, sizeof(cat_chars));
  620.                                 strcpy( cat_chars, to_roman(numeral1|numeral2).c_str() );
  621.                                 strcat( cat_chars, to_roman(numeral2).c_str() );
  622.                                 cout << cat_chars;
  623.                                 goto end_of_while_statement;
  624.                              }
  625.                         default: {
  626.                                 cout << to_roman(numeral1|numeral2);
  627.                                 goto end_of_while_statement;
  628.                              }
  629.                     }
  630.                   }
  631.         }
  632.        
  633.        
  634.         end_of_while_statement:
  635.         cout << "\n";
  636.     }
  637.     return 0;
  638. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement