Suppose a punch recipe calls for a given amount of orange soda, measured in ounces. int amount 32; We can compute the number of 12-ounce cans needed, assuming that the amount does not evenly divide into 12: int cans_needed amount / 12 + 1; Adjust the formula so that it also works for amounts that evenly divide into 12. And compute the number of ounces that are left over. For example, if 32 ounces are required, we need 3 cans and have 4 ounces left over. 1 #include 2 #include 3 4 using namespace std; 5 6 int main() 7 { 8 9 10 11 12 13 14 15 16 17 // Other values will be set during testing. // Your program needs to work with any amount. int amount 32; // Compute the number of cans needed and the ounces Left over // Your code goes here cout << "Cans needed: << cans_needed << endl; cout << "Ounces left over: " << left over << endl;
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
![In city street grids, intersections are often defined by two integers, counting the position of horizontal and vertical streets
(sometimes called streets and avenues). Imagine traveling from position (h₁, ₁) to (h₂, v₂). How many blocks do you
traverse?
(h₂, v₂)
(h₁, v₂)
Even though there are many possible routes, the distance only depends on the differences h₂ h₁ and v₂ - ₁. However, you
need to take the absolute value because the differences might be negative.
Complete the following program that prints the number of blocks traveled, given the origin and destination of the trip (which will
change as your code is tested).
#include <<math>
3
4 using namespace std;
5
6 int main()
7 {
8
9
10
11
12
13
5555555
14
15
16
17
18
19
int h1;
int v1;
int h2;
int v2;
cin >> h1;
cin >> v1;
cin >> h2;
cin >> v2;
/* Your code goes here */
cout << "Distance: << distance << endl;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7adc1e26-5311-43de-8756-917a6c93d6ba%2Ff2572b4f-2cec-4563-8600-003fa4684ce0%2Fvxqsmkg_processed.png&w=3840&q=75)
![Suppose a punch recipe calls for a given amount of orange soda, measured in ounces.
int amount = 32;
We can compute the number of 12-ounce cans needed, assuming that the amount does not evenly divide into 12:
int cans_needed = amount / 12 + 1;
Adjust the formula so that it also works for amounts that evenly divide into 12. And compute the number of ounces that are left
over. For example, if 32 ounces are required, we need 3 cans and have 4 ounces left over.
1 #include <iostream>
2 #include <<math>
3
4 using namespace std;
5
6 int main()
7 {
8
9
10
11
12
13
14
15
16
17
// Other values will be set during testing.
// Your program needs to work with any amount.
int amount = 32;
// Compute the number of cans needed and the ounces left over
// Your code goes here
cout << "Cans needed: << cans_needed << endl;
cout << "Ounces left over: << left over << endl;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7adc1e26-5311-43de-8756-917a6c93d6ba%2Ff2572b4f-2cec-4563-8600-003fa4684ce0%2Fpbgakr3_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)