0

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 "<<num2<<endl;} //get another number
while (num2 == 0);
cout << "(10) ";
cout<<num1 << " / " << num2 <<" = ";
cin >> userInput;
answer=num1/num2

Any ideas?

3
Contributors
4
Replies
5
Views
12 Years
Discussion Span
Last Post by LostinCode
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

0

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!

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.