NOTE: in mathematics, division by zero is undefined. So, in C++, division by zero is always an error. Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer division with truncation will do). HOWEVER: if any value read in is not valid input, just print the message "INVALID".
.
.
Click on the title for the solution
.
.
cin>>callsReceived>>operatorsOnCall;
if (operatorsOnCall>0) {cout<<callsReceived/operatorsOnCall;}
else cout<<"INVALID";
.
Click on the title for the solution
.
.
This is the answer:
:
cin>>callsReceived>>operatorsOnCall;
if (operatorsOnCall>0) {cout<<callsReceived/operatorsOnCall;}
else cout<<"INVALID";
cin >>callsReceived;
ReplyDeletecin >>operatorsOnCall;
if ((operatorsOnCall>0)&& (callsReceived >= 0)) {
cout << (callsReceived/operatorsOnCall);
}
else {
cout << "INVALID";
}
What happens when you divide a number by zero?
ReplyDeleteSee here Division by zero