Thread: Russian Peasent

  1. #31
    Registered User
    Join Date
    Sep 2008
    Posts
    101
    ok so ive changed it, but im getting zero for everything now.. at least i think i fixed what u suggested
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(floor(y/2)==1){
          
        if(fmod(y,2)==0){
    	a=a+x;
        x=x*2;
        y=(y/2);
          
        }
        else{
          x=x*2;
          y=(y/2);
    
    
      }
      }
      outD(a);
      
      }

  2. #32
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Lucid15 View Post
    ok so ive changed it, but im getting zero for everything now.. at least i think i fixed what u suggested
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(floor(y/2)==1){
          
        if(fmod(y,2)==0){
    	a=a+x;
        x=x*2;
        y=(y/2);
          
        }
        else{
          x=x*2;
          y=(y/2);
    
    
      }
      }
      outD(a);
      
      }
    Oh for crying out loud.
    Code:
    while(y!=0)
    How hard is this?

  3. #33
    Registered User
    Join Date
    Sep 2008
    Posts
    101
    ok so ive changed everything and NOW IT WORKS! i believe...
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(y!=0){
          
        if(fmod(y,2)!=0){
    	a=a+x;
        x=x*2;
        y=(y/2);
          
        }
        else{
          x=x*2;
          y=(y/2);
    
    
      }
      }
      outD(a);
      
      }

  4. #34
    Registered User
    Join Date
    Sep 2008
    Posts
    101
    Sorry for the trouble tabstop, but thank you so much for your help. Im an idiot.

  5. #35
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Call my crazy but I would probably write this same code as demonstrated bellow.

    Or maybe cleaned up to...
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(y!=0){     
        if(!(y&3)){
          a+=x;
          x+=x;
          y/=2;    
        }
        else{
          x+=x;
          y/=2;
        }
      }
      outD(a);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 05-22-2009, 07:03 AM
  2. Russian student attacks Estonia
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-25-2008, 10:35 AM
  3. Russian stuffffffffff
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 04-22-2004, 01:21 PM