This is anothe exercise I got, but I haven't done anything just because I need how to get the code, as if I would write it in a piece of paper:

_____

Write the code that prompts the user to enter two integer numbers, numerator and denominator. Your program should determine(output) if the number is divisible by the denominator.

NOTE: your are not allowed to use % operator!.


THANKS

William Hemsworth commented: No effort, in all three of your threads. -1

Recommended Answers

All 6 Replies

The way that you do this exercise is you bust out your handy dandy computer, use your problem solving skills to work it out yourself, try to compile the program, and if you still have problems you ask on a forum. You've just posted 3 of your homework assignments with absolutely no code and no effort put into doing them yourself. Common what are you trying to do? It's your homework not ours.

Doesnt exactly compile for me for whatever reason but im guess thats how you go about it... found it on this forum... And yes you should search how to do stuff rather than getting spoon fed cuz no one will just write code without you putting in effort... im only helping you start off... if the following compiles for you then ur good other than that edit and do whatever you want...

#include <stdio.h>
#include <math.h>
#include <iostream>
#include <windows.h>

using namespace std;  
  
  int main(void)
  {
     int numerator=42, denominator=5, quotient, <strong class="highlight">remainder</strong>; 
     divide(numerator,denominator,&quotient,&<strong class="highlight">remainder</strong>);
     printf("numerator   = %d\n", numerator);
     printf("denominator = %d\n", denominator);
     printf("quotient	= %d\n", quotient);
     printf("<strong class="highlight">remainder</strong>   = %d\n", <strong class="highlight">remainder</strong>);
     
     if (remainder > 0)
     {
     cout<<"Calculations did not come out to a whole number!\n";
     }
     else
     cout<<"The remainder is 0, calculations = whole number
     
     return 0;
  }
  
  /* my output
  numerator   = 42
  denominator = 5
  quotient	= 8
  <strong class="highlight">remainder</strong>   = 5
  */

LOL. This code is half C and half C++. Maybe call it "C squared ++" ;)

I don't know what you're doing with the posts, but preview them before you post. You have some odd tags. Perhaps you pasted html code rather than plain text code and pasted it here. Hit "Preview Post" to make sure things look right, then fix the post if there's something wrong.

Is there some "divide" function you didn't post? If not, there's your error.

Here are the libraries you can use. If your function isn't in one of them, you have to write it yourself.

http://www.cplusplus.com/reference/

Ok well I got your PM but the thing is if you cant use the modulo sign (%) then you may be able to use this... you better be greatful cuz this is a formula i had to work out myself on pencil paper...

#include <iostream>
#include <windows.h>
#include <math.h>
#include <cmath>

using namespace std;

int main()
{
  int a,d,q,r;
  cout<<"Numerator: \n";
  cin>> a;                      //a is divident (numerator)
  cout<<"Denominator: \n";
  cin>> d;
                          
  r= abs(a - (q * d));       // d is divisor  (denominator)
  q=((a) / (d));         //q is quotient    (plain old value without remainder)
                    
                    //r is remainder
    
  cout<< a <<" / "<< d <<" = "<< q <<" with remainder "<< r <<endl;  
        
Sleep(3000);
    return 0;
}

RELEASE NOTE: there is a bug in my code for some reason... when I ask it to output remainder, it outputs a huge!!! number which is impossible looking at the code... pick numerator 10, denominator 2, and itll still give u remainder of like 2300000 or something stupid like that so if u fix that then ur good or maybe its just my computer

Ok well I got your PM but the thing is if you cant use the modulo sign (%) then you may be able to use this... you better be greatful cuz this is a formula i had to work out myself on pencil paper...

#include <iostream>
#include <windows.h>
#include <math.h>
#include <cmath>

using namespace std;

int main()
{
  int a,d,q,r;
  cout<<"Numerator: \n";
  cin>> a;                      //a is divident (numerator)
  cout<<"Denominator: \n";
  cin>> d;
                          
  r= abs(a - (q * d));       // d is divisor  (denominator)
  q=((a) / (d));         //q is quotient    (plain old value without remainder)
                    
                    //r is remainder
    
  cout<< a <<" / "<< d <<" = "<< q <<" with remainder "<< r <<endl;  
        
Sleep(3000);
    return 0;
}

RELEASE NOTE: there is a bug in my code for some reason... when I ask it to output remainder, it outputs a huge!!! number which is impossible looking at the code... pick numerator 10, denominator 2, and itll still give u remainder of like 2300000 or something stupid like that so if u fix that then ur good or maybe its just my computer

It's not your computer. It's your code. I'd explain what is wrong with it, but that might mean sebassn could put absolutely no effort into this and get the complete answer. sebassn, three verbatim homework posts with absolutely no effort. AND you're asking for help via PM, which is a big no-no on this forum. Read the rules, all of them. Here's the main one.

http://www.daniweb.com/forums/announcement8-2.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.