Thread: syntax errors

  1. #31
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    it is giving me wrong output.
    Code:
    #include <iostream.h>
    
    void addfraction (int w, int x, int y, int z, int& newnumerator, int& newdenominator)
    	{
    	int number1, number2;
       number1=w*z;
       number2=y*x;
       newdenominator=z*x;
       newnumerator=number1+number2;
       };
    
    int GCD(int a, int b )
    {
    	int remainder, quotient, divisor, numerator;
    		if (a > b)
    		{
          	remainder=a%b;
    			quotient=a/b; divisor=b;
    		}
          	else
         	   {
    				remainder=b%a;
    				quotient=b/a;divisor=a;
             }
    
    		
    		while( remainder!=0 )
    		{
    			numerator=divisor;
    			divisor=quotient;
    			remainder=numerator%divisor;
    			quotient=numerator/divisor;
    		}
          return divisor;
        
    }
    
    int simplify(int a, int GCD )
    {
    	int product;
          {
          {
          	product=a / GCD;
    		}
          }
    return product;
    }
    
    
    int main()
    {
    	int w, x,y,z,a,b;
       char junk;
    
    	cout << "Value of first numerator: ";
    	cin >> w;
    	cout << "Value of first denominator: ";
    	cin >> x;
       cout << "Value of second numerator: ";
    	cin >> y;
    	cout << "Value of second denominator: ";
    	cin >> z;
       addfraction(w,x,y,z,a,b);
    
    	cout << "\nThe Greatest Common Divisor of "
    	     << a << " and " << b << " is " << GCD(a, b) << endl;
        cout << "\nThe simplified fraction of "
             << a << " and " << b << " is " << simplify(a,GCD(a, b)) << " and "<<
                simplify(b,GCD(a, b)) << endl;
       cout<<a<<'/'<<b<<endl;
       cin >> junk; //This input allows for display.
      //take care of improper fractions
    	return 0;
    }
    It is giving me huge numbers as answers. Also I am supposed to account for whole numbers and dont know how.

  2. #32
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you should check your GDC function in debugger... it has some logical errors
    or add traces after each step...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #33
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    It worked before I had to add the fractions together.

  4. #34
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I suppose it worked but not for all possible inputs
    Code:
    int GCD(int a, int b )
    {
    	do
    	{
    		int big = max(a,b);
    		int small = min(a,b);
    		a = big%small;
    		b = small;
    	}while(a);
    	return b;
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. errors syntax
    By bazzano in forum C Programming
    Replies: 2
    Last Post: 09-30-2005, 02:44 AM
  4. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM
  5. Expression/Declaration Syntax Errors
    By fuh in forum C++ Programming
    Replies: 2
    Last Post: 01-15-2003, 06:49 PM