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