How to put two programs into one etc help
I have finished both my programs and have attached them below. I want to put them into one program and have an options menu to chose either program. i was wondering if anyone could help me do this coz its really annoying me, i keep getting it wrong :P thanks in advance
Code:
FIRST PROGRAM CODE TO CONVERT ROMAN TO ARABIC:
#include <conio.h>;
#include <ctype.h>;
#include <stdio.h>;
#include <stdlib.h>;
#include <string.h>;
int main (void)
{
int arabic1 = 0;
int arabic2 = 0;
int stringpos = 0;
int counter = 0;
int roman[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char tempRoman = ' ';
char input[15] = "";
printf ("Roman Numeral Converter for values between 1 and 3999\n\n");
printf ("Enter Roman Numeral(s): ");
while ((tempRoman != '\n') && (stringpos < 15))
{
tempRoman = toupper(getchar());
switch (tempRoman)
{
case 'V': case 'L': case 'D':
if ((stringpos > 0) && (input[stringpos - 1] == tempRoman))
{
printf ("\nInput values not correct!\n\n");
}
else
{
input[stringpos++] = tempRoman;
}
break;
case 'I': case 'X': case 'C': case 'M':
if (counter <= 3)
{
input[stringpos++] = tempRoman;
}
counter++;
if ((counter > 3) && (input[stringpos - 2] == tempRoman))
{
printf ("\nInput values not correct!\n\n");
exit(100);
}
if ((stringpos > 1) && ((counter > 3) || (input[stringpos - 2] != tempRoman)))
{
counter = 1;
}
break;
case '\n':
break;
default: printf ("\nInput values not correct!\n\n"); exit(100);
}
}
for (counter = 0; counter <= stringpos; counter++)
{
switch (input[counter])
{
case 'I': roman[counter] = 1; break;
case 'V': roman[counter] = 5; break;
case 'X': roman[counter] = 10; break;
case 'L': roman[counter] = 50; break;
case 'C': roman[counter] = 100; break;
case 'D': roman[counter] = 500; break;
case 'M': roman[counter] = 1000; break;
}
}
for (counter = 0; counter <= stringpos; counter++)
{
if (roman[counter] >= roman[counter + 1])
{
arabic2 = roman[counter];
}
if ((roman[counter] == (roman[counter + 1] / 10)) || (roman[counter] == (roman[counter + 1] / 5)))
{
arabic2 = roman[counter + 1] - roman[counter];
counter++;
}
if (arabic2 < roman[counter + 1])
{
printf ("\nInput values not correct!\n\n");
}
arabic1+= arabic2;
}
printf ("\nArabic Equivalent is: %d\n\n", arabic1);
printf ("\n\n\t\t\t...Press any key to exit.");
getch();
return 0;
}
SECOND PROGRAM CODE ARABIC TO ROMAN:
#include <stdio.h>
#include <conio.h>
#include <string.h>
char *a2roman (int value, char *c1, char *c2, char *c3);
int main (void)
{
int arabicNum = 1;
int result;
char roman[15] = "";
do
{
printf ("Enter an integer in the range of 1 to 3999: \n\t");
scanf ("%d", &arabicNum);
}
while ((arabicNum < 1) || (arabicNum > 3999));
if ((arabicNum <= 3999) && (arabicNum >= 1000))
{
result = arabicNum / 1000;
strcat (roman, a2roman(result, "M", " ", " "));
arabicNum -= (result * 1000);
}
if ((arabicNum < 1000) && (arabicNum >= 100))
{
result = arabicNum / 100;
strcat (roman, a2roman(result, "C", "D", "M"));
arabicNum -= (result * 100);
}
/* Obtain the value of tens */
if ((arabicNum < 100) && (arabicNum >= 10))
{
result = arabicNum / 10;
strcat (roman, a2roman(result, "X", "L", "C"));
arabicNum -= (result * 10);
}
if ((arabicNum < 10) && (arabicNum >= 1))
{
strcat (roman, a2roman(arabicNum, "I", "V", "X"));
}
printf ("The Roman numeral is: \n\t%s\n\n", roman);
printf ("\t\t ...Press any key to exit.");
getch();
return 0;
}
char *a2roman (int value, char *c1, char *c2, char *c3)
{
int i;
char rRoman[15] = "";
/* If value = 1, 2, 3 */
if ((value >= 1) && (value <= 3))
{
for (i = 0; i < value; i++)
strcat (rRoman, c1);
}
/* If value = 5, 6, 7, 8 */
if ((value >= 5) && (value <= 8))
{
strcat (rRoman, c2);
for (i = 0; i < (value - 5); i++)
strcat (rRoman, c1);
}
/* If value = 4 */
if (value == 4)
{
strcat (rRoman, c1);
strcat (rRoman, c2);
}
/* If value = 9 */
if (value == 9)
{
strcat (rRoman, c1);
strcat (rRoman, c3);
}
return (rRoman);
}