Hi! I'm new to C++ and I was wondering how to get a statement using selection statements (if and else). Like, a statement that is executed in case condition is true, and in case it is not, a different statement is executed.
If the output doesn't have a remainder, this statement will show up on the output (This is how should my output look like. For example:
#include <iostream>
usingnamespace std;
int main (){
int number, divisor, qoutient, remainder;
cout<<"Please enter a number: ";
cin>>number;
cout<<"Please enter a divisor: ";
cin>>divisor;
qoutient = number / divisor;
remainder = number % divisor;
//if the qoutient doesn't have a remainder, this statement will show up on the output
if (qoutient>1){
cout << "\n" << divisor << " divides the number " << number << "." << endl;
cout << number <<"/"<< divisor << "=" << qoutient << endl;
}
//if the qoutient has a remainder, this statement will show up instead of the other statement without the remainder
else (remainder){
cout << "\n" << divisor << " does not divide the number " << number << "." << endl;
cout << number <<"/"<< divisor << "=" << qoutient << "." << remainder << endl;
}
return 0;
}
else does not have a condition (as in, no parentheses or anything in between them). It runs if the if statement immediately above it had a false condition (and thus didn't run).
Also, your condition on line 18 needs to be tweaked. It might help to reread your comment just above it: