Hello all, I am hopeing someone can help me out on this, Yes this is homework and i have been trying to figure it out for the past couple of days and it is due tonihgt, the teacher wont really help any of us.We need to write a program in C++ that Computes two rational fractions. It needs to read the inputs of the two fractions (N and D) that are inputed and then print them in 2D form:

23

66

Then it must mutlply the two fractions togeher and print the anwser in traditional two-dimenstional form. The Part that im getting confussed on is we are soposed to use a counter to count the amount of numbers in the fraction so i can calculate the right amount of ---- between the numbers.

Here is the program I started to write for this. Im not sure if im gogin down the right road or not, Please Help

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
/* Declarations & Initialization
of Variables, Symbolic Constants */
int a,b,ab;
double AB;

*Part A, User Input 1*/
printf("This Program Computes Rational Fractions\n\n");
printf("Please Enter Your Value For The First Numerator And Denominator: ");
scanf("%i %i",&a,&b);
printf("%i %i",a/b);

/* Exit Program */
return EXIT_SUCCESS;
}

Here is what the TA gave us to help with the counter , I tried to run this and it wont run.

#define max(a,b) (((a) > (b)) ? (a) : (b))
*/



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

int count_digits(int n);

int main()
{
int numDigits;
numDigits=count_digits(6000);
printf(" number of digits =%d",numDigits);
return 0;
}
int count_digits(int n)
{
int digits=1;

while(n/10 >0)
{
n=n/10;
digits=digits +1;
}

return digits;

}

>I tried to run this and it wont run.
It looks largely okay, can you describe how it doesn't run?

Im not sure thats my problem. They tried to cram this class into three weeks only meeting once a week for two hours and no one has a clue what they are doing.

I think what Narue meant was, how is it not working correctly?

>and no one has a clue what they are doing
Get used to it. Confusion is a close friend to every programmer. :)

>Im not sure thats my problem.
You said it doesn't work. Describe what it does as opposed to what you expected it to do. That might not be the problem, but we'll have a hard time helping you without details.

Ok i figured out the main part of the problem, I got it to work , know all i need to do is to get it to print out the fractions in 2D.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main ()
{
/* Declarations & Initialization
of Variables, Symbolic Constants */
int n1,d1,n2,d2,nr,dr;
/*User Input 1*/
printf("This Program Computes Rational Fractions\n\n");
printf("Please Enter Your Value For The First Numerator And Denominator: ");
scanf("%i %i",&n1,&d1);
printf("\n%i/%i",n1,d1);

printf("\n\nPlease Enter Your Value For The Secound Numerator And Denominator: ");
scanf("%i %i",&n2,&d2);
printf("\n%i/%i",n2,d2);
/* Caluclations */
nr = n1 * n2;
dr = d1 * d2;
/* Result */
printf("\n\nFinal Result is: \n\n%i/%i\n\n",nr,dr);
/* Exit Program */
return EXIT_SUCCESS;
}

You mean like this?

4
_
6

I think that's the best you can do. Print the numerator, newline, _ (underscore), newline and the denominator.

Looking good. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.