Thread: Converting to Modular

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    43

    Converting to Modular

    Is there an easy way to convert programs into modular? I just realised my code has to be in modular and have no clue how to convert my code easily

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #include <ctype.h>
    
    int main()
    
    
    {
    
    	int fifty, twenty, ten, five, result;
    	char option;
    
        printf("This program will calculate change\n");
    	printf("Please input the number of cents between 5 - 95\n");
    	printf("Input must be in mulitples of 5\n");
    	printf("\n");
    
    	do
     	{
    	printf("Do you wish to continue? (Y/N): \n");
    
    	option = getch();
    	option = toupper (option);
    	}
    	while (!((option=='Y') || (option=='N')));
    		printf("%c\n",option);
    	if (option=='Y')
    	{
    
    			while (1)
    			{
    
    			printf("\nEnter Customers Change:\n");
    			scanf("%d", &result);
    
    			if ((result<0) || (result>95) || (result%5>0))
    				printf("Invalid Input!\n");
    			else{
    
    			fifty = result / 50;
    			result %= 50;
    			twenty = result / 20;
    			result %= 20;
    	      		ten = result / 10;
    	      	 	result %= 10;
    			five = result / 5;
    			result %= 5;
    
    			printf("The Correct Change =\n", result);
    
    			if (fifty > 1)
        				printf("%d Fifty cent piece's.\n", fifty);
    			if (fifty == 1)
    				printf("%d Fifty cent piece.\n", fifty);
    			if (twenty > 1)
           				printf("%d Twenty cent piece's.\n", twenty);
    			if (twenty == 1)
           				printf("%d Twenty cent piece.\n", twenty);
    			if (ten > 1)
           				printf("%d Ten cent piece's\n", ten);
    			if (ten == 1)
           				printf("%d Ten cent piece.\n", ten);
    			if (five > 1)
           				printf("%d Five cent piece's\n", five);
    			if (five == 1)
    				printf("%d Five cent piece.\n", five);
    			}
    			}
    
    	}
    return(0);
    }
    any help would be cool

  2. #2
    Registered User jdragyn's Avatar
    Join Date
    Sep 2009
    Posts
    96
    The first question here (based on your usage of the word rather than any intent to be rude or anything) is: Do you know what "modular" means? (And if so, what do you think it means?)

    The next question would be: How much have you learned about functions?

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Those sentences are structured as if there were a programming language called "Modular". This does not make sense to us.

    I suspect that you've mistakenly assumed "Modular" was being used as a noun when communicated to you, when in fact it was probably actually being used as an adjective. Remember, an adjective describes a noun.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm guessing you mean it has to have different functions, for different purposes. How about:

    1) A menu function, called from main() to display the name of the program and version, as well as the options the user can choose from - get input, in other words.
    2) A processing function, called from menu()
    3) An output function, called from menu(), after the program returns from processing.

    Input, processing, and output, are very standard functions for most programs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-20-2009, 07:39 AM
  2. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  3. Modular math
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-01-2003, 08:35 AM
  4. Modular Division problem
    By Malek in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2003, 06:08 PM
  5. converting string to float
    By twhubs in forum C Programming
    Replies: 1
    Last Post: 09-16-2001, 09:02 AM