syntax errors

This is a discussion on syntax errors within the C++ Programming forums, part of the General Programming Boards category; it is giving me wrong output. Code: #include <iostream.h> void addfraction (int w, int x, int y, int z, int& ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    you should check your GDC function in debugger... it has some logical errors
    or add traces after each step...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

  4. #34
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Page 3 of 3 FirstFirst 123
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, 02:29 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. errors syntax
    By bazzano in forum C Programming
    Replies: 2
    Last Post: 09-30-2005, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21