-9

The program should look like this (USER INPUT IN BOLD):

    Welcome to the Fraction Arithmetic Program.
    -------------------------------------------
    Your problems with fractions can be solved here. Enter a fraction arithmetic problem (Example 2/5 -4/7).

1/2 + 1/4

    The answer is 6/8.

Prompt: Your program should handle the operations of addition, subtraction, multiplication, and division. The answer foes not have to be in lowest terms for this version of the program.

Plan your program so that it is modular. Have the input done in one module, the output done in a second module, and the calculation done in the third. Put each module in a separate source code file. The function main() should reside in its own module and be the program without using any global variables.

So far what I got down is:

#include <conio.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main( void )
{   
    int a,b,c,d,e,f,g,h;
    int oper;
    float n1, n2, d1, d2;
    float n11, n22, d11, d22;
    int problem; 
    int restart;
    char operation;

    printf("Welcome to the FRACTION ARITHMETIC PROGRAM\n-------- ---------- -------\n");
    OUT:
    printf("Indicate which operation ( 1=Add , 2=Subtract , 3=Multiply , 4=Divide ): ");
    scanf("%d", &oper);

    if (oper== 1 | oper== 2 | oper== 3 | oper== 4){   
        printf("Enter your two fractions with one space in between: ");
        scanf("%f/%f %f/%f", &n1, &d1, &n2, &d2);
        switch(oper){   
            case 1:
                a=n1*d2+n2*d1;
                b=d1*d2;
                printf("The answer is %d/%d", a,b);
                if (b=0)
                    printf ("ILLEGAL INPUT");
                break;
            case 2:
                c=n1*d2-n2*d1;
                d=d1*d2;
                printf("The answer is %d/%d", c,d);
                if (d=0)
                    printf ("ILLEGAL INPUT");
                break;
            case 3:
                e=n1*d2;
                f=n2*d1;
                printf("The answer is %d/%d", e,f);
                if (f=0)
                    printf ("ILLEGAL INPUT"); 
                break;
            case 4:
                g=n1*d1;
                h=n2*d2;
                printf("The answer is %d/%d", g,h);
                if (h=0)
                    printf ("ILLEGAL INPUT");
                break;
        }
    }

    printf("\t Another Problem (1=Yes or 2=No)? ");
    scanf("%d", &restart);

    if(restart==1)
        goto OUT;
    if (restart==2)
        goto DONE;

    DONE: 
    printf("Goodbye and thank you.");
    return 0;
}

I'm not understanding the whole source code file and making the program modular. Can someone please help, anything is greatly appreciated!!! Thank you

Kugelblitz
  • 582
  • 5
  • 24
humdyez
  • 11
  • 1
  • 2
    This looks like a homework assignment that you're asking someone else to do for you. – Shane Dec 07 '15 at 00:11
  • 2
    "Have the input done in one module, the output done in a second module, and the calculation done in the third". That's a pretty good guide already on how to make your code modular. It means write code for each of those operations in a seperate function. – kaylum Dec 07 '15 at 00:15

1 Answers1

1

Making it modular means that you have to break this source code up in to different files. In this case, you are asked to provide 3 modules, plus a file containing the main() method. This means you should have the following files:

fraction_arithmetic_program.c // Contains the main method.
fraction_arithmetic_input.c   // Handles all the user input.
fraction_arithmetic_input.h   // Header to the above file.
fraction_arithmetic_output.c  // Handles all the output back to the user.
fraction_arithmetic_output.h  // Header to the above file.
fraction_arithmetic_calc.c    // Does the necessary calculations.
fraction_arithmetic_calc.h    // Header to the above file.

In the fraction_arithmetic_program.c file, you have your main method. This file includes all three: fraction_arithmetic_input.h, fraction_arithmetic_output.h, and fraction_arithmetic_calc.h. This means, that inside your main file (/Main method), you can use all the functions provided to you by the modules fraction_arithmetic_input.c, fraction_arithmetic_output.c, and fraction_arithmetic_calc.c.

In those 3 .c files, you have to put the respective methods. HOW you want to break this code up in to these 3 files is up to you, but you are given some pretty specific constraints as to how you have to do it, so I would stick to those. If you have any questions, let me know.

Kugelblitz
  • 582
  • 5
  • 24