syntax errors

This is a discussion on syntax errors within the C++ Programming forums, part of the General Programming Boards category; smiles are caused Code: :D add space or... don't remember code-tags can help also...

  1. #16
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    smiles are caused
    Code:
    :D
    add space or... don't remember
    code-tags can help also
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

    fuction int simplify2 - missing closing } in the function body
    Last edited by vart; 12-13-2006 at 10:49 AM.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    could you fix your indentetion and post a last code
    also pointing the lines containing errors (with comments) will help
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    you have to many closing } in the GCD function
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    Code:
    int simplify2(int b, int GCD )
    {
    	int product2;      // error 1
          {       // error 2
          do
          {
             product2=b / GCD;
    		}
          while ( b!=0 );
          }
    
    return product2;
    }
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

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

Page 2 of 3 FirstFirst 123 LastLast
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, 12:10 AM
  5. Expression/Declaration Syntax Errors
    By fuh in forum C++ Programming
    Replies: 2
    Last Post: 01-15-2003, 05:49 PM

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