How could I reduce the length of the code?

Help fixing code for a program in C to reduce fractions.?

  • Im having trouble fixing some errors.... My code: #include <stdio.h> void get_fraction (int *original_num, int *original_denom) { do { *original_num = -1; printf("Please enter a fraction as two positive integers\n"); printf("Numerator: \n"); scanf("%d", original_num); while (getchar() != '\n'); if (*original_num <= 0) { printf ("Please enter an integer greater than 0\n"); } } while (*original_num <= 0); do { *original_denom = -1; printf("Denominator: \n"); scanf("%d", original_denom); while (getchar() != '\n'); if (*original_denom <= 0) { printf ("Please enter an integer greater than 0\n"); } } while (*original_denom <= 0); } void reduce (int *reduced_num, int *reduced_denom) { int gcd (int *reduced_num, int *reduced_denom) { if (*reduced_num % *reduced_denom == 0) { return *reduced_denom; } return gcd(*reduced_denom, *reduced_num % *reduced_denom); } } int main() { int original_num = 0; int original_denom = 0; int reduced_num = 0; int reduced_denom = 0; printf ("This program reduces a fraction that you enter\n"); printf ("to its lowest terms\n\n"); get_fraction(&original_num, &original_denom); reduce(original_num, original_denom, &reduced_num, &reduced_denom); printf ("%d/%d reduced to its lowest terms is %d/%d\n", original_num, original_denom, reduced_num, reduced_denom); return 0; } ERRORS: fractions.c: In function âgcdâ: fractions.c:40: warning: passing argument 1 of âgcdâ makes pointer from integer without a cast fractions.c:40: warning: passing argument 2 of âgcdâ makes pointer from integer without a cast fractions.c: In function âmainâ: fractions.c:56: warning: passing argument 1 of âreduceâ makes pointer from integer without a cast fractions.c:56: warning: passing argument 2 of âreduceâ makes pointer from integer without a cast fractions.c:56: error: too many arguments to function âreduceâ Any advice, please help, but give me real solutions, no hints, ive tried multiple things already?

  • Answer:

    Ok, so I used Borland Turbo C++ to compile it... Things that pop into my eyes: void reduce (int *reduced_num, int *reduced_denom) { int gcd (int *reduced_num, int *reduced_denom) { What is this? Looks like you are declaring a function inside of a function... You can't do that... Then when you use reduce: you give it 2 int types and 2 pointers (adresses) though in the declaration you state that you need only 2 pointers. Gives several type mismatches. EDIT: in reduce(original_num, original_denom, &reduced_num, &reduced_denom); removing the first 2 int types leaves only the declaration error.

Ryan at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.