Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Beginner's Question II

Beginner's Question II

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason K Dove
    wrote on last edited by
    #1

    You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd

    C M M R 4 Replies Last reply
    0
    • J Jason K Dove

      You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd hold1 = iDenominator / gcd; ^^^^^^^^^^ what's up with this ? Is a bit missing in the middle ? This won't compile because the for loop has no closing bracket. Does the for loop have a ; at the end of it ? If so, it won't work either. Also, if you want the for loop to take into account more than one line, they need to also be enclosed in {}. hold2 = iNumerator / gcd; if(hold1 == hold2) same = hold1; } Here is a gcd function int gcd(int m, int n) { if (m==0) return n; else return gcd( n%m, m); } Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

      1 Reply Last reply
      0
      • J Jason K Dove

        You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd

        M Offline
        M Offline
        markkuk
        wrote on last edited by
        #3

        Your code sample looks garbled, please put it between <pre> and </pre> tags and use < for the < sign and > for >

        1 Reply Last reply
        0
        • J Jason K Dove

          You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Just as a guess, the division looks suspect. You are dividing two integers, which returns an integer (throwing away the remainder), and that might not be what you want. You are also comparing (iDenominator/gcd) == (iNumerator/gcd) which (assuming you change those variables to floating-point) is true only if iDenominator == iNumerator, so check your algorithm again. --Mike-- http://home.inreach.com/mdunn/ #include "buffy_sig"

          1 Reply Last reply
          0
          • J Jason K Dove

            You are so right,the screwy code would help greatestCommonDenominator() { int gcd, same, hold1, hold2; if(iNumerator < iDenominator){ for(gcd=1;gcd

            R Offline
            R Offline
            Rejeesh
            wrote on last edited by
            #5

            int GCD(int x, int y) { //Swap if x < y if(x < y) { int t = x; x = y; y = t; } while(x%y) { int r = x%y; x =y; y = r; } return y; } void (*p[10]) (void (*)());

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups