954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Division with remainder

Hello...

I am writing a C++ program that needs to code division with remainders. My current code does not work.

//Division
if (num2==0)
do {num2 = rand() % 10;
cout<<"new number "<> userInput;
answer=num1/num2

Any ideas?

LostinCode
Newbie Poster
3 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Im not sure what your trying to do but the modulas '%' operator shows the remainder between division of two numbers. If I am guessing at what you want right you'll want to do something like this

int holdRemainder;
int value1 =10;
int value2 = 3;
std::cout<<value1<<" / "<<value2<<" = "<<value1/value2<<std::endl;
holdRemainder = value1 % value2
std::cout<<"With a remainder of "<<holdRemainder;

Also even when your post that little of code it's nice to use code tags

prog-bman
Junior Poster
109 posts since Nov 2004
Reputation Points: 14
Solved Threads: 4
 

Thank you!

I'm trying not to use too much code..It looks like someone else in my class is also here asking for help..I am doing the same final assignment as the person looking for a function to add..etc.

I will try this change.

Thanks again!

LostinCode
Newbie Poster
3 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

At least you seem a more friendly and smarter person than your classmate ;)

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

I agree...

I'll just write it off as them being frustrated with the upcoming deadline..:-)

The code worked..I am happy now.

Will try to get some sleep!

This is a great site for those who need help!

LostinCode

LostinCode
Newbie Poster
3 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You