Thread: syntax errors

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    66

    syntax errors

    I am having some syntax errors with this program. My compiler is borland. What am I doing wrong?

    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;
          {
          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 "
             << simplify1(w,GCD(w, x)) << " and "<<
                simplify2(x,GCD(w, x)) endl;
       cin >> junk; //This input allows for display.
    	return 0;
    }

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    What and where?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. posting error text will be helpful
    2. #include <iostream>
    3. you should use std namespace
    4. simplify1 and simplify2 have endless loop
    5. GCD does not check that values are bigger than 0
    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

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Vart, for your points #2 and #3, seeing as how he's using Borland, I wouldn't be surprised if it was a version that didn't support the new <iostream>/namespace std include style.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Yes, my college is cheap and wont buy visual studio so I have to use the ".h" after everything.

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    there is a free MSVC++ Expert compiler
    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

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    Error: sort and search hoskins beta v1.cpp(10,1):Declaration syntax error
    Error: sort and search hoskins beta v1.cpp(53,6):Expression syntax
    Error: sort and search hoskins beta v1.cpp(53,6):'bubblesort(long *,int)' cannot return a value
    Error: sort and search hoskins beta v1.cpp(53,6):Return statement missing ;
    Error: sort and search hoskins beta v1.cpp(58,6):Declaration syntax error
    Error: sort and search hoskins beta v1.cpp(136,1):Compound statement missing }
    Last edited by Salem; 12-13-2006 at 11:33 AM. Reason: Stop smilies munging error message

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    My instructor is using borland as well. I did a little work in visual studio once and sent it to him and he couldnt figure out that he had to change it from "using namespace std;".

  9. #9
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Quote Originally Posted by vart
    there is a free MSVC++ Expert compiler
    Yes, but if he wants his code to compile in the labs at his school, I doubt he has the option of using a different compiler. Plus if he's only working in the school labs, he wouldn't even have the ability to install that.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    those smilys arent supposed to be there.

  11. #11
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by nesagsar
    those smilys arent supposed to be there.
    errors are from another project
    there is no bubblesort function in this one
    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

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    A school which isn't teaching you about namespaces and how to use them really isn't preparing you for a programming career when you're done.

    Namespaces appeared in 1998, which means they'll be about 10 years old by the time you get through college.

    "Sorry kid, you don't know about namespaces" is really gonna suck come job hunting time.

    There is simply NO excuse for not using any one of the current crop of C++ compilers on the basis of cost, because they're all free. It's just down to lame tutors just teaching what they know, no matter how old and out of date it is.
    Try and explain this to them, especially if you're the one handing over the dollars for the course.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    sorry about the errors, I am trying to debug 4 programs at once.

  14. #14
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    these are the correct errors

    Info :fraction hoskins beta v2.cpp: out of date with destination fraction hoskins beta v2.obj
    Info : fraction hoskins beta v2.cpp: source date 11:51:00 AM 12/11/2006 destination date <unknown>
    Info :Compiling C:\Documents and Settings\labpc\Desktop\fraction hoskins beta v2.cpp
    Error: fraction hoskins beta v2.cpp(39,5)eclaration syntax error
    Error: fraction hoskins beta v2.cpp(40,8)eclaration terminated incorrectly
    Error: fraction hoskins beta v2.cpp(65,40):Statement missing ;

  15. #15
    Registered User
    Join Date
    Nov 2006
    Posts
    66
    and the stupid smilys persist.

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