Thread: How to put two programs into one etc help

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    10

    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);
    }

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Take both main() functions and rename them to reflect which program they are from. Then write a new main() function which acts as your menu and calls one of those two functions as needed.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    10
    ok thanks mate. i now have this as my main function:

    Code:
    void main()
    {
    
    	int modeno;
    	
    	printf("Roman Numeral and Arabic Converter: Choose a Mode\n\n");
    	printf("1. Roman to Arabic\n");
    	printf("2. Arabic to Roman\n\n");
    	printf("Enter Mode Number: ");
    	scanf("&#37;d", &modeno);
    
    	switch(modeno)
    	{
    		case '1': 
    		romantoarabic();
    		break;
    		
    		case '2':
    		arabictoroman();
    		break;
    	
    		default:
    		printf("\nIncorrect Mode Choice");
    		break;
    	}
    }
    How would i go about calling these functions in the switch statement above? sorry im really new to all this :P

    int romantoarabic (void)
    int arabictoroman (void)

    thanks

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    what is wrong with the way you are calling them now?

    main should be
    int main not void - read FAQ
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    10
    i changed the above code to:

    Code:
    	switch(modeno)
    	{
    		case '1': 
    		int romantoarabic();
    		break;
    		
    		case '2':
    		int arabictoroman();
    		break;
    	
    		default:
    		printf("\nIncorrect Mode Choice\n\n");
    		
    	}
    }
    and the program now runs, but every time i type 1 or 2 into the option is says the default message and wont load either of my functions. hellpo ;p

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sigh.
    You obviously don't know much.
    I'd recommend you to go back to your books or tutorials or whatever and read on about the language.
    Switch case is wrong - you're confusing char with int.
    Function calling is wrong, too.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    int romantoarabic();
    is declaration of the function, not the call to the function

    the call to the function was as before
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #8
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    What Elysia is trying to eloquently state is that in your cases you have '1' instead of 1, and the same for the next one. '1' is actually resolved to be 49. Every char has a numerical value associated with it. The char of 1 has 49 associated with it (on most systems, anyway since this is the ASCII and Unicode values). If you take the single quotes off of it, you're then correctly analyzing an integer of 1 with an integer of 1, not a an integer of 1 with a char that has a representation of 1.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    10
    okay so ive gone back to as before to call the functions and corrected the switch statement.

    Code:
    int main(void)
    {
    
    	int modeno;
    	
    	printf("Roman Numeral and Arabic Converter: Choose a Mode\n\n");
    	printf("1. Roman to Arabic\n");
    	printf("2. Arabic to Roman\n\n");
    	printf("Enter Mode Number: ");
    	scanf("&#37;d", &modeno);
    
    	switch(modeno)
    	{
    		case 1:
    		romantoarabic();
    		break;
    		
    		case 2:
    		arabictoroman();
    		break;
    		
    		default:
    		printf("\nIncorrect Mode Choice\n\n");
    		break;
    		
    	}
    }
    now it comes up with these errors when building:

    error C3861: 'romantoarabic': identifier not found
    error C3861: 'arabictoroman': identifier not found
    error C2365: 'romantoarabic' : redefinition; previous definition was 'formerly unknown identifier'
    error C2365: 'arabictoroman' : redefinition; previous definition was 'formerly unknown identifier'

    i know i dont know much but i still have to do this. please help me by telling me how have i incorrectly named the functions and how can i just get this switch statement to call the two programs correctly? as i said they both work fine individually :P im just confused and been lookin at this for too long

    please help

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You put all the code in the same file right?

  11. #11
    Registered User
    Join Date
    Dec 2007
    Posts
    10
    yea here it is:

    Code:
    #include <conio.h>;
    #include <ctype.h>;
    #include <stdio.h>;
    #include <stdlib.h>;
    #include <string.h>;
    
    
    int main(void)
    {
    
    	int modeno;
    	
    	printf("Roman Numeral and Arabic Converter: Choose a Mode\n\n");
    	printf("1. Roman to Arabic\n");
    	printf("2. Arabic to Roman\n\n");
    	printf("Enter Mode Number: ");
    	scanf("&#37;d", &modeno);
    
    	switch(modeno)
    	{
    		case 1:
    		romantoarabic();
    		break;
    		
    		case 2:
    		arabictoroman();
    		break;
    		
    		default:
    		printf("\nIncorrect Mode Choice\n\n");
    		break;
    		
    	}
    }
    
    
    int romantoarabic (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))	/* If appear more of one time, then finish the program */ 
    				{
    						printf ("\nInput values not correct!\n\n");
    				}
    
    				else 
    				{ 
    					input[stringpos++] = tempRoman; 
    				}
    				break;
    			
    			case 'I': case 'X': case 'C': case 'M':	/* I, X, C can appear until 3 times */
    				
    				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))) /* If the 3 incurs counter get to be 3 but the preceding char */
    				{															
    					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;
    }
    
    
    char *a2roman (int value, char *c1, char *c2, char *c3);
    
    int arabictoroman (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);
    	}
    
    	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);
    }

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    int romantoarabic (void);
    char *a2roman (int value, char *c1, char *c2, char *c3);
    Add these to the top of your source file. Read declarations too.
    Always use declarations.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    10
    Thanks a lot Elysia forgot about prototypes etc arf

  14. #14
    Registered User
    Join Date
    Dec 2007
    Posts
    10
    ok new problem, sorry to be such a pain but its quite important ;[

    it now loads fine and i can choose both options, but when i chose option one which is the romantoarabic function, it seems to automatically enter a value on selection and carry out the formulas without waiting for user input.
    the second function works fine and does wait.

    Code:
    /* ************************************************************************ */
    /* Object:	Convert an roman numeral to arabical, the input can be a number */
    /*				between 1 to 3999.											*/
    /* Jason Holt | 14/12/07 | v1.0                                             */
    /* ************************************************************************ */
    
    /* Header files */
    
    #include <conio.h>;
    #include <ctype.h>;
    #include <stdio.h>;
    #include <stdlib.h>;
    #include <string.h>;
    
    int romantoarabic (void);
    int arabictoroman (void);
    char *a2roman (int value, char *c1, char *c2, char *c3);
    
    int main(void)
    {
    
    	int modeno;
    	
    	printf("Roman Numeral and Arabic Converter: Choose a Mode\n\n");
    	printf("1. Roman to Arabic\n");
    	printf("2. Arabic to Roman\n\n");
    	printf("Enter Mode Number: ");
    	scanf("&#37;d", &modeno);
    
    		switch(modeno)
    		{
    			case 1:
    			romantoarabic();
    			break;
    		
    			case 2:
    			arabictoroman();
    			break;
    		
    			default:
    			printf("\nIncorrect Mode Choice\n\n");
    			break;
    		
    	}
    }
    
    
    int romantoarabic (void)
    {	
    	int arabic1 = 0;							/* Decimal value of roman numeral      */
    	int arabic2 = 0;						    /* Decimal value of each roman numeral */
    	int stringpos = 0;    						/* Roman Letter String position                     */
    	int counter = 0;							/* 3 incurs counter                    */
    	int roman[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};	/* Array that stores the value of each roman letter */
    	char tempRoman =' ';						/* Contain the temporal roman letter   */
    	char input[15] = "";						/* Contain the input string            */
    	
    	printf ("Roman Numeral Converter for values between 1 and 3999\n\n");
    	printf ("Enter Roman Numeral(s): ");
    	scanf ("&c", &tempRoman);
    	/* Read from keyboard until appear an <ENTER> */
    	while ((tempRoman != '\n') && (stringpos < 15))
    	{	
    		switch (tempRoman) 
    		{
    			/* V, L D only can appear one time */
    			case 'V': case 'L': case 'D':
    				
    				if ((stringpos > 0) && (input[stringpos - 1] == tempRoman))	/* If appear more of one time, then finish the program */ 
    				{
    						printf ("\nInput values not correct!\n\n");
    				}
    				/* If appear one time, save the char in the string that stores the characters of roman numerals */
    				else 
    				{ 
    					input[stringpos++] = tempRoman; 
    				}
    				break;
    			
    			case 'I': case 'X': case 'C': case 'M':	/* I, X, C can appear until 3 times */
    				
    				if (counter <= 3)	/* If appear correctly, save the char in the string that stores the characters of roman numeral */		
    				{					
    					input[stringpos++] = tempRoman;
    				}
    					counter++;
    
    				if ((counter > 3) && (input[stringpos - 2] == tempRoman)) /* If appear more of 3 times, then finish the program */
    				{
    					printf ("\nInput values not correct!\n\n");
    					exit(100);
    				}
    									
    				if ((stringpos > 1) && ((counter > 3) || (input[stringpos - 2] != tempRoman))) /* If the 3 incurs counter get to be 3 but the preceding char */
    				{																		   /*is different of current, then reset the 3 incurs counter */
    					counter = 1;
    				}
    				
    				break;
    			
    			case '\n':	/* Invalidate the \n char as default char */
    				
    				break;
    			default: 	printf ("\nInput values not correct!\n\n");		/* If the input is an invalid char then finish the program  */
    			exit(100);	
    						
    	    }   
         }
    
    	/* Reutilization of counter variable as index of iterations for no create
    		a new variable and then optimize the program  */
    	
    	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;
    		}
    	}
    
    	/* Do a sum over stored numbers */
    
    	for (counter = 0; counter <= stringpos; counter++) 
    	{
    		
    		if (roman[counter] >= roman[counter + 1])	/* Add decimal value of each roman numeral */ 
    		{
    			arabic2 = roman[counter];
    		}
    		
    		/* If precedent number is less than current value and this is 10% */
    		/* or 5% of current value, then do a difference between two roman */
    		/* numerals to obtain the final value i.e. IX = 10 - 1 = 9        */
    
    		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])	/* If precedent number is less than current value and not is 10% or */
    											/* 5% of current value, then finish the program  */ 
    		{
    			 printf ("\nInput values not correct!\n\n"); 
    		}
    			arabic1+= arabic2;
    	}
    
    	
    	printf ("\nArabic Equivalent is: %d\n\n", arabic1);		/* Diplay result in the screen */
    	
    	printf ("\n\n\t\t\t...Press any key to exit.");		/* Press any key to finish the program */
    	getch();
    	
    	return 0;	/* Return succesfully */
    }
    
    
    char *a2roman (int value, char *c1, char *c2, char *c3);
    
    int arabictoroman (void)
    {
    	int arabicNum = 1; /* Initialization for read althought one time  */
    	int result;              /* "result" store the position value           */
    	char roman[15] = "";     /* "roman" contain the roman-numeral string    */
    
    	/* This cicle allow to continue if "arabicalNumber" to be in the range */
    	do
    	{
    		/* Print a message to user */
    		printf ("Enter an integer in the range of 1 to 3999: \n\t");
    
    		/* Read the value */
    		scanf ("%d", &arabicNum);
    	}
    	while ((arabicNum < 1) || (arabicNum > 3999));
    
    	/* Obtain the value of thousands */
    	if ((arabicNum <= 3999) && (arabicNum >= 1000))
    	{
    		result = arabicNum / 1000;
    		strcat (roman, a2roman(result, "M", " ", " "));
    		arabicNum -= (result * 1000);
    	}
    
    	/* Obtain the value of hundreds */
    	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);
    	}
    
    	/* Obtain the value of units */
    	if ((arabicNum < 10) && (arabicNum >= 1))
    	{
    		strcat (roman, a2roman(arabicNum, "I", "V", "X"));
    	}
    
    	/* Display the Roman numeral */
    	printf ("The Roman numeral is: \n\t%s\n\n", roman);
    	printf ("\t\t      ...Press any key to exit.");
    	getch();
    
    	/* Succesfull return */
    	return 0;
    }
    
    char *a2roman (int value, char *c1, char *c2, char *c3)
    {
    	int i;	/* "i" is the index of the iteration */
    	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);
    }
    this is seriously irritating and i dnno how to fix it GRR sorry to ask for more help

  15. #15
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You could try this in main():

    Code:
    scanf("&#37;d", &modeno);
    getchar();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Communication between programs?
    By johny145 in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2005, 10:14 PM
  2. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  3. Possible to write adaptive programs?
    By crag2804 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 06-16-2003, 04:35 PM
  4. How to (let the code) put an object into a game.
    By FromHolland in forum C++ Programming
    Replies: 5
    Last Post: 04-10-2003, 03:44 AM
  5. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM