Term does not evaluate to function taking 2 arguments? Bugger.

This is a discussion on Term does not evaluate to function taking 2 arguments? Bugger. within the C++ Programming forums, part of the General Programming Boards category; Working on a program for the Euclidian algorithm, and it's giving me a bit of trouble. I think I have ...

  1. #1
    OHNOES! A PURPLE ZOMBIE! Sennet's Avatar
    Join Date
    Sep 2005
    Posts
    20

    Unhappy Term does not evaluate to function taking 2 arguments? Bugger.

    Working on a program for the Euclidian algorithm, and it's giving me a bit of trouble. I think I have the math and such down, but it's giving me an unusual error. I believe I know what it's trying to tell me, but I can't figure out exactly what I've done wrong for the life of me!

    Ahem. My code so far (not complete, might I add)

    Code:
    #include <iostream>
    using namespace std;
    void prompt(int&, int&);
    int gcf (int, int);
    int reduce (int, int);
    
    void main()
    {
    	int num1 = 0;
    	int num2 = 0;
    	int gcf = 0;
    
    	prompt (num1, num2);
        
    	cout << "Fraction so far: " << num1 << "/" << num2 << endl;
    	
    	gcf (num1, num2);
    }
    
    void prompt(int &a, int &b)
    {
    	cout << "Enter your numerator: ";
    	cin >> a;
    	cout << "Enter your denominator: ";
    	cin >> b;
    }
    
    int gcf (int num1, int num2)
    {
      int remainder=1;
      int gcf;
    
      while (remainder!=0)
      {
      remainder=num1%num2;
      gcf=num2%remainder;
      }
    	  return gcf;
    
    }
    The 17th line:
    Code:
    gcf (num1, num2);
    is giving me trouble. As far as I know, it's correct for my purposes, but the compiler justi sn't happy with it. What have I missed?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    > void main()
    main returns an int - see FAQ

    > int gcf (int, int);
    A function

    > int gcf = 0;
    A variable with the same name, in a nearer scope to the function name.

    Guess which one the compiler tries to "call" ?

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    38
    try renaming the variable int gcf ..... its the same as the name of your function

  4. #4
    OHNOES! A PURPLE ZOMBIE! Sennet's Avatar
    Join Date
    Sep 2005
    Posts
    20

    Thumbs up

    ...D'oh! XD

    Gods. Sorry. Running on caffeine and brain fumes. Right. Gonna go change. XD

    EDIT: Oh, glorious. Now it bombs when I run it. Back to the drawing board.

    EDIT AGAIN: Allow me to rephrase that: HELP! DX

    The code, editted as per your advice:

    Code:
    #include <iostream>
    using namespace std;
    void prompt(int&, int&);
    int gcf (int, int);
    void reduce (int&, int&);
    
    void main()
    {
    	int num1 = 0;
    	int num2 = 0;
    
    	prompt (num1, num2);
        
    	cout << "Fraction so far: " << num1 << "/" << num2 << endl;
    
    	reduce (num1, num2);
    
    	cout << "GCF: " << gcf (num1, num2) << endl;
    
    	cout << "reduced: " << num1 << "/" << num2 << endl;
    }
    
    void prompt(int &a, int &b)
    {
    	cout << "Enter your numerator: ";
    	cin >> a;
    	cout << "Enter your denominator: ";
    	cin >> b;
    }
    
    int gcf (int num1, int num2)
    {
      int remainder=1;
      int gc;
    
      while (remainder!=0)
      {
      remainder=num1%num2;
      gc=num2%remainder;
      }
    	  return gc;
    
    }
    
    void reduce (int &n1, int &n2)
    {
    	n1 = n1/n2;
    	n2 = n2/n2;
    }
    Now, it compiles, and even runs for a bit, but it spontaneously erros and dies as soon as it tries to call the gcf function.
    Last edited by Sennet; 01-17-2006 at 11:31 AM.

  5. #5
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
      remainder=num1%num2;
      gc=num2%remainder;
    if remainder is 0 that will result in a division by 0 -> bombs.
    You should think about the logic of that function.
    if num1%num2 is non-zero you have a infinite loop.
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 10-20-2008, 10:23 AM
  2. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  3. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 08:15 AM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21