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.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images