Solved

compiling errors

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now