Solved

compiling errors

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

734 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