syntax errors

This is a discussion on syntax errors within the C++ Programming forums, part of the General Programming Boards category; I am having some syntax errors with this program. My compiler is borland. What am I doing wrong? Code: #include ...

  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
    Portugal
    Posts
    7,412
    What and where?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


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

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

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

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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.

Page 1 of 3 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