Solved

compiling errors

Posted on 2003-10-25
3
250 Views
Last Modified: 2013-12-14
here is my code, I'm getting 3 errors and can't seem to figure out what is causing them, I'm using Visual Studio .NET as the compiler.

GCD.cpp(28) : error C2144: syntax error : 'int' should be preceded by ')'
GCD.cpp(28) : error C2660: 'computegcd' : function does not take 0 parameters
GCD.cpp(28) : error C2059: syntax error : ')'

#include <iostream>
#include <fstream>
using namespace std;

int computegcd (int m, int n);

main()

{
      int r, n, m;
      int count =1;
      int mtemp, ntemp;
      int gcd;
      ifstream infile;
      ofstream outfile;
      infile.open("datafile.dat");
      outfile.open("gcdlist.dat");
 
      while (infile)
      {
            //outfile << "Enter first integer ";
            infile >> m;
            outfile << "\nThe first integer is: " << m << endl;
            //outfile << "Enter second integer ";
            infile >> n;
            outfile << "The second integer is: " << n << endl;
            
this is line 28      gcd = computegcd (int m, int n);

            outfile << "\nThe GCD is: " << gcd << endl;
            outfile << "\n";
            outfile << "\n";
            }
      

infile.close();
outfile.close();
return 0;

}

int computegcd (int m, int n)
{
      int r, ntemp, mtemp;
      if (m < n)
      {
            ntemp = n;
            mtemp = m;
            m = ntemp;
            n = mtemp;
      }
      
            r = n % m;
            while(r != 0)
      {
            n = m;
            m = r;
            r = n % m;
      }

      return m;

}

thanks for the help
0
Comment
Question by:Orlando15767
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
mnashadka earned 125 total points
ID: 9620707
You don't put types in function calls, only in the function declaration/definition.  Change:
gcd = computegcd (int m, int n);
To:
gcd = computegcd (m, n);

Good luck.
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 9620714
By the way, you can simplify your swap in computegcd to:
if(m < n)
{
  int temp = n;
  n = m;
  m = temp;
}

There's also a swap function in the STL that would do this like:
swap(m, n);

Hope this helps.
0
 
LVL 1

Author Comment

by:Orlando15767
ID: 9620733
works like a charm now, thanks for the help..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question