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

if (num2==0)
do {num2 = rand() % 10;
cout<<"new number "<<num2<<endl;} //get another number
while (num2 == 0);
cout << "(10) ";
cout<<num1 << " / " << num2 <<" = ";
cin >> userInput;

Any ideas?

Recommended Answers

All 4 Replies

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

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!

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

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!


Be a part of the DaniWeb community

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