Thread: syntax errors

  1. #16
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    smiles are caused
    Code:
    :D
    add space or... don't remember
    code-tags can help also
    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

  2. #17
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    simplify2(x,GCD(w, x)) << endl;

    fuction int simplify2 - missing closing } in the function body
    Last edited by vart; 12-13-2006 at 11:49 AM.
    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. #18
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    I fixed thboth of those but I still get errors.

    Code:
    Info :Compiling C:\DOCUMENTS AND SETTINGS\LABPC\DESKTOP\fraction hoskins beta v2.cpp
    Error:  fraction hoskins beta v2.cpp(39,5):Declaration syntax error
    Error:  fraction hoskins beta v2.cpp(40,8):Declaration terminated incorrectly
    Error:  fraction hoskins beta v2.cpp(47,3):Unexpected }

  4. #19
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Cool, no smilys.

  5. #20
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    could you fix your indentetion and post a last code
    also pointing the lines containing errors (with comments) will help
    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

  6. #21
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Here is the new code.

    Code:
    #include <iostream.h>
    
    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 )   //error 1
    		{
    			numerator=divisor;
    			divisor=quotient;
    			remainder=numerator%divisor;
    			quotient=numerator/divisor;
    		}
          return divisor;
        
    } //error2
    
    int simplify1(int a, int GCD )
    {
    	int product1;
          {
          do
          {
          	product1=a / GCD;
    		}
          while ( a!=0);
          }
    return product1;
    }
    
    int simplify2(int b, int GCD )
    
    	int product2;  //error3
          { //error4
          do
          {
             product2=b / GCD;
    		}
          while ( b!=0 );
          }
    
    return product2;
     } //error5
    
    int main()
    {
    	int w, x;
       char junk;
    
    	cout << "This program allows calculating the GCD\n";
    	cout << "Value of first numerator: ";
    	cin >> w;
    	cout << "Value of first denominator: ";
    	cin >> x;
    
    
    	cout << "\nThe Greatest Common Divisor of "
    	     << w << " and " << x << " is " << GCD(w, x) << endl;
        cout << "\nThe simplified fraction is "
             << w << " and " << x << simplify1(w,GCD(w, x)) << " and "<<
                simplify2(x,GCD(w, x)) << endl;
    
       cin >> junk; //This input allows for display.
    
    	return 0;
    }
    and here are the errors
    Code:
    Info :Compiling C:\Documents and Settings\labpc\Desktop\fraction hoskins beta v2.cpp
    Warn :  fraction hoskins beta v2.cpp(16,2):Function should return a value
    Warn :  fraction hoskins beta v2.cpp(16,2):'numerator' is declared but never used
    Warn :  fraction hoskins beta v2.cpp(16,2):'divisor' is assigned a value that is never used
    Warn :  fraction hoskins beta v2.cpp(16,2):'quotient' is assigned a value that is never used
    Warn :  fraction hoskins beta v2.cpp(16,2):'remainder' is assigned a value that is never used
    Error:  fraction hoskins beta v2.cpp(18,8):Declaration terminated incorrectly
    Error:  fraction hoskins beta v2.cpp(27,2):Unexpected }
    Error:  fraction hoskins beta v2.cpp(44,5):Declaration syntax error
    Error:  fraction hoskins beta v2.cpp(45,8):Declaration terminated incorrectly
    Error:  fraction hoskins beta v2.cpp(54,3):Unexpected }

  7. #22
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    wow, my indentation really does suck. sorry.

  8. #23
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you have to many closing } in the GCD function
    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

  9. #24
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    this is the new code.

    Code:
    #include <iostream.h>
    
    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 simplify1(int a, int GCD )
    {
    	int product1;
          {
          do
          {
          	product1=a / GCD;
    		}
          while ( a!=0);
          }
    return product1;
    }
    
    int simplify2(int b, int GCD )
    
    	int product2;      // error 1
          {       // error 2
          do
          {
             product2=b / GCD;
    		}
          while ( b!=0 );
          }
    
    return product2;
    
    
    int main()
    {
    	int w, x;
       char junk;
    
    	cout << "This program allows calculating the GCD\n";
    	cout << "Value of first numerator: ";
    	cin >> w;
    	cout << "Value of first denominator: ";
    	cin >> x;
    
    
    	cout << "\nThe Greatest Common Divisor of "
    	     << w << " and " << x << " is " << GCD(w, x) << endl;
        cout << "\nThe simplified fraction is "
             << w << " and " << x << simplify1(w,GCD(w, x)) << " and "<<
                simplify2(x,GCD(w, x)) << endl;
    
       cin >> junk; //This input allows for display.
    
    	return 0;
    }
    and here is the errors

    Code:
    Info :Compiling C:\Documents and Settings\labpc\Desktop\fraction hoskins beta v2.cpp
    Error:  fraction hoskins beta v2.cpp(44,5):Declaration syntax error
    Error:  fraction hoskins beta v2.cpp(45,8):Declaration terminated incorrectly

  10. #25
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    int simplify2(int b, int GCD )
    {
    	int product2;      // error 1
          {       // error 2
          do
          {
             product2=b / GCD;
    		}
          while ( b!=0 );
          }
    
    return product2;
    }
    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

  11. #26
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Alright, I fixed that.

    I got an email from the teacher. He wants us to add two fractions together and simplify now. if he keeps adding stuff to our assignments we will never get it done.

  12. #27
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Code:
    #include <iostream.h>
    
    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;
          {
          //do
          {
          	product=a / GCD;
    		}
          //while ( a!=0);
          }
    return product;
    }
    /*
    int simplify1(int a, int GCD )
    {
    	int product1;
          {
          do
          {
          	product1=a / GCD;
    		}
          while ( a!=0);
          }
    return product1;
    }
    
    int simplify2(int b, int GCD )
    {
    	int product2;      // error 1
                 // error 2
          do
          {
             product2=b / GCD;
    		}
          while ( b!=0 );
    
    return product2;
    }  */
    
    int main()
    {
    	int w, x,y,z;
       char junk;
    
    	cout << "This program allows calculating the GCD\n";
    	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;
    
    
    	cout << "\nThe Greatest Common Divisor of "
    	     << w << " and " << x << " is " << GCD(w, x) << endl;
        cout << "\nThe simplified fraction is "
             << w << " and " << x << simplify(w,GCD(w, x)) << " and "<<
                simplify(x,GCD(w, x)) << endl;
    
       cin >> junk; //This input allows for display.
    
    	return 0;
    }

  13. #28
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    do
    {
          	product1=a / GCD;
    } while ( a!=0);
    a is not changed inside the loop
    so if the condition was true in the beginning - it will be true ever
    so the loop will be endless
    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

  14. #29
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    here is the new code

    Code:
    #include <iostream.h>
    
    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;
       char junk;
    
    	cout << "This program allows calculating the GCD\n";
    	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;
    
    
    	cout << "\nThe Greatest Common Divisor of "
    	     << w << " and " << x << " is " << GCD(w, x) << endl;
        cout << "\nThe simplified fraction of "
             << w << " and " << x << " is " << simplify(w,GCD(w, x)) << " and "<<
                simplify(x,GCD(w, x)) << endl;
    
       cin >> junk; //This input allows for display.
    
    	return 0;
    }

  15. #30
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    is it working?
    seems to be ok, except the indentation and to many unnecacery breckets...

    also GCD(w,x) is calculated 3 times - you can calculate it once and store in the temporary varyable.
    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