Solved

compiling errors

Posted on 2003-10-25
3
248 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
  • 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

803 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