Having a problem with gcd

This is a discussion on Having a problem with gcd within the C++ Programming forums, part of the General Programming Boards category; I'm having a problem with gcd. I don't know why it gives me a red squiggly under the gcd(lower case) ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    36

    Having a problem with gcd

    I'm having a problem with gcd. I don't know why it gives me a red squiggly under the gcd(lower case) at this line
    GCD = gcd(y, x % y);

    Any help?


    Code:
    // Greatest Common Divisor.cpp : Defines the entry point for the console application.
    //
    
    //	=========
    //	Libraries
    //	==================
       #include "stdafx.h"
       #include <iostream>
       #include <math.h>
       #include <stdio.h> 
    //	==================
    
    //  ==========
    //  Namespaces
    //	====================
    	using namespace std;
    //  ====================
    
    //  ===================
    //	Function Prototypes
    //	=====================
    	void WelcomeBanner();
    	void GetIntegers(int&, int&);
    //	=====================
    
    
    
    // ==============
    
    	int main( ) { // main()
    
    		int x;
    		int y;
    		int GCD;
    
    		WelcomeBanner();
    		GetIntegers(x, y);
    
    		if (y == 0 ){
    			
    			cout << "GCD = " << x << endl;
    		}
    		else
    			GCD = gcd(y, x % y);
    			cout << "GCD = " << GCD << endl;
    		
    	
    		
    
    
    	return 0;
    	}// main()
    //	========
    
    
    //  =========================
    //	Function WelcomeBanner()
    //	=========================
    	void WelcomeBanner(){
    
    		cout << "================================================" << endl;
    		cout << "Welcome to my program that will give you the   |" << endl << "greatest common divisor of your two numbers =) |" << endl;
    		cout << "================================================"<< endl << endl;
    
    	}// Welcome banner
    //	==================
    
    //	====================
    //	Function GetIntegers
    //	====================
    	void GetIntegers(int& num1, int& num2){
    
    		cout << "Please enter an integer that you want me to find the GCD of." << endl;
    		cin >> num1;
    
    		cout << "Please enter another integer that you want me to find the GCD of." << endl;
    		cin >> num2;
    
    	}//GetIntegers
    //	==============

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    36
    Bump!

  3. #3
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    Have you written the gcd function somewhere becuase there is no gcd function in cmath.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    36
    Well in my book it says

    gcd(x, y) = x if y = 0
    gcd(y,x%y) if y =/= 0

    So I'm a little confused..

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Your book gave you the mathematics that can be used to implement the function. It's your turn now
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    That's the concept of GCD. You have to write that gcd function yourself.
    Code:
    int gcd(int x, int y)
    {
      translate that part into code here
    }
    "All that we see or seem
    Is but a dream within a dream." - Poe

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    36
    Awwww. Okokok. I can do that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  2. Visual Studio Linker problem or my problem?
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-13-2004, 12:32 AM
  3. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 08:14 AM
  4. Texture Problem(I got the NeHe tut working, but I have a problem)
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 12-02-2001, 09:40 PM

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