Answer:
A Program was written to carry out some set activities. below is the code program in C++ in the explanation section
Explanation:
Solution
CODE
#include <iostream>
using namespace std;
int main() {
string name; // variables
int number;
cin >> name >> number; // taking user input
while(number != 0)
{
// printing output
cout << "Eating " << number << " " << name << " a day keeps the doctor away." << endl;
// taking user input again
cin >> name >> number;
}
}
Note: Kindly find an attached copy of the compiled program output to this question.
In this exercise we have to use the knowledge in computational language in C++ to describe a code that best suits, so we have:
The code can be found in the attached image.
What is looping in programming?In a very summarized way, we can describe the loop or looping in software as an instruction that keeps repeating itself until a certain condition is met.
To make it simpler we can write this code as:
#include <iostream>
using namespace std;
int main() {
string name; // variables
int number;
cin >> name >> number; // taking user input
while(number != 0)
{
// printing output
cout << "Eating " << number << " " << name << " a day keeps the doctor away." << endl;
// taking user input again
cin >> name >> number;
}
}
See more about C++ at brainly.com/question/19705654
Rewrite this if/else if code segment into a switch statement int num = 0; int a = 10, b = 20, c = 20, d = 30, x = 40; if (num > 101 && num <= 105) { a += 1; } else if (num == 208) { b += 1; x = 8; } else if (num > 208 && num < 210) { c = c * 3; } else { d += 1004; }
Answer:
public class SwitchCase {
public static void main(String[] args) {
int num = 0;
int a = 10, b = 20, c = 20, d = 30, x = 40;
switch (num){
case 102: a += 1;
case 103: a += 1;
case 104: a += 1;
case 105: a += 1;
break;
case 208: b += 1; x = 8;
break;
case 209: c = c * 3;
case 210: c = c * 3;
break;
default: d += 1004;
}
}
}
Explanation:
Given above is the equivalent code using Switch case in JavaThe switch case test multiple levels of conditions and can easily replace the uses of several if....elseif.....else statements.When using a switch, each condition is treated as a separate case followed by a full colon and the the statement to execute if the case is true.The default statement handles the final else when all the other coditions are false