Question
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
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".
Assume that an int variable age has been declared and already given a value and assume that a char variable choice has been declared as well. Assume further that the user has just been presented with the following menu:
- S: hangar steak, red potatoes, asparagus
- T: whole trout, long rice, brussel sprouts
- B: cheddar cheeseburger, steak fries, cole slaw
(Yes, this menu really IS a menu!)
Write some code that reads a single character (S or T or B) into choice. Then the code prints out a recommended accompanying drink as follows:
If the value of age is 21 or lower, the recommendation is "vegetable juice" for steak, "cranberry juice" for trout, and "soda" for the burger. Otherwise, the recommendations are "cabernet", "chardonnay", and "IPA" for steak, trout, and burger respectively. Regardless of the value of age, your code should print "invalid menu selection" if the character read into choice was not S or T or B
Assume the int variables i and result, have been declared but not initialized. Write a for loop header -- i.e. something of the form
for ( . . . )
for the following loop body:
result = result * i;
When the loop terminates, result should hold the product of the odd numbers between 10 and 20.
NOTE: just write the for loop header; do not write the loop body itself.
-
Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a for loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and total.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started