Question

C++ CodeLabs

Not too sure what is wrong with the following code. I believe that it is something to do with the denominator being zero but not sure.

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 operatorsOnCalland print out the number of calls received per operator (integer division with truncation will do).

code:

cin >> callsReceived;
cin >> operatorsOnCall;
if ( operatorsOnCall > 0)
cout << (callsReceived / operatorsOnCall );
0 1
Add a comment Improve this question Transcribed image text
Answer #1
Answer:
cin >> callsReceived;
cin >> operationsOnCall;
if(operationsOnCall>0 && callsReceived>0)
    cout << (callsReceived/operationsOnCall);
else
    cout << "INVALID";

Note: Please comment below if you have any doubtsPlease up vote the solution if it helped. Thanks!

Add a comment
Answer #2

cin >> callsReceived;

cin >> operatorsOnCall;


if (callsReceived >= 0 && operatorsOnCall > 0)

{

    cout << (callsReceived/operatorsOnCall);

}

else

{

    cout << "INVALID";

}


source: HARDWORK
answered by: garuda6
Add a comment
Know the answer?
Add Answer to:
C++ CodeLabs
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • photos arent too go so the answer there is right but im trying to figure put...

    photos arent too go so the answer there is right but im trying to figure put why codelap took operatorsoncall as > and callsrecieved aas >= if that makes any sense. why not both > or >= Workbend M Mathway Math Pr. Rate My Professors Vonida Vol Instructions Display stdout NOTE: In mathematics, division by zero is undefined. So, in C++, division by zero is always an error Given a int variable named calls Received and another int variable named...

  • Note: In mathematics, division by zero is undefined . so, in c++, division by zero is always an error given an integer v...

    Note: In mathematics, division by zero is undefined . so, in c++, division by zero is always an error given an integer variable named callsReceived and another integer 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 divison with truncation will do).

  • Write in a program in C. NOTE: in mathematics, division by zero is undefined. So, in...

    Write in a program in C. 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".

  • C++ Given a int variable named callsReceived and another int variable named operatorsOnCall, write the necessary...

    C++ 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". Valid input for operatorsOnCall is any value greater than 0. Valid input for callsReceived is any value greater than or equal to 0. Revel for...

  • HELP PYTHON 3.0 (NOT JAVA) 1.HTTP is the protocol that governs communications between web servers and...

    HELP PYTHON 3.0 (NOT JAVA) 1.HTTP is the protocol that governs communications between web servers and web clients (i.e. browsers). Part of the protocol includes a status code returned by the server to tell the browser the status of its most recent page request. Some of the codes and their meanings are listed below: 200, OK (fulfilled) 403, forbidden 404, not found 500, server error Given an int variable status, write a statement that prints out, on a line by...

  • What is wrong with the following code snippet? int main() { int width = 10; height...

    What is wrong with the following code snippet? int main() { int width = 10; height = 20.00; cout << "width = " << width << " height = " << height << endl; return 0; } The code snippet uses an uninitialized variable. The code snippet uses an undefined variable. The code snippet attempts to assign a decimal value to an integer variable. The code snippet attempts to assign an integer value to a decimal variable.

  • You have been developing a Fraction class for Teacher’s Pet Software that contains several fields and...

    You have been developing a Fraction class for Teacher’s Pet Software that contains several fields and functions. a. Add four arithmetic operators, +, -, *, and /. Remember that to add or subtract two Fractions, you first must convert them to Fractions with a common denominator. You multiply two Fractions by multiplying the numerators and multiplying the denominators. You divide two Fractions by inverting the second Fraction, then multiplying. After any arithmetic operation, be sure the Fraction is in proper...

  • NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------...

    NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------------------------------------------------- Tasks to complete: ---------------------------------------------------------------------------------------------------------------------------------------- given code: ----------------------------------------------------------------------------------------------------------------------------------------------- main.cpp #include <iostream> #include <iomanip> #include "fractionType.h" using namespace std; int main() { fractionType num1(5, 6); fractionType num2; fractionType num3; cout << fixed; cout << showpoint; cout << setprecision(2); cout << "Num1 = " << num1 << endl; cout << "Num2 = " << num2 << endl; cout << "Enter the fraction in the form a / b: "; cin >> num2; cout << endl; cout <<...

  • Please use C++ and add comments to make it easier to read. Do the following: 1)...

    Please use C++ and add comments to make it easier to read. Do the following: 1) Add a constructor with two parameters, one for the numerator, one for the denominator. If the parameter for the denominator is 0, set the denominator to 1 2) Add a function that overloads the < operator 3) Add a function that overloads the * operator 4) Modify the operator<< function so that if the numerator is equal to the denominator it just prints 1...

  • C++ Object Oriented assignment Can you please check the program written below if it has appropriately...

    C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT