Hi I'm having difficulty with this remainder program. I'm supposed to make a program that takes 2 numbers and determines which is larger and then divides them. It has to display a remainder, but if a remainder doesn't exist then only the quotient is displayed.
I got the program to work if I do say 15/15 and no remainder exists but I'm not sure how to program it to not show a remainder if I do 15/3.
Code:
#include <iostream>
#include <cmath> //included just in case its needed
using namespace std;
void main()
{
//variables
int num1;
int num2;
int quo; //quotient
int rem; //remainder
//prompt and input
cout<< "Enter a number: ";
cin>>num1;
cout<<"\n";
cout<< "Enter another number: ";
cin>>num2;
cout<<"\n";
//calculate
quo=num1/num2;
rem=num1%num2;
if (num1>num2)
{
rem=num1%num2;
quo=num1/num2;
}
else if(num2>num1)
{
rem=num2%num1;
quo=num2/num1;
cout<< "The quotient is: "<< quo;
cout<<"\n";
cout<< "With a remainder of: "<<rem;
cout<<"\n";
}
else if(rem==0)
{
quo=num1/num2;
cout<<" The quotient is: "<< quo;
cout<<"\n";
cout<<"There is no remainder.";
}
cout<<"\n";
system ("pause");
}