Exercise 5A: #include \"stdafx.h\" #include <iostream> using namespace std; int
ID: 3587239 • Letter: E
Question
Exercise 5A:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int flag;
cout << "Enter an Flag value: ";
cin >> flag;
if (flag >= 40)
printf("The Wire is Red");
else if (flag >= 30 && flag <= 40)
printf("The Wire is Blue");
else if (flag > 10 && flag < 30)
printf("The Wire is Green");
else
printf("The Wire is White");
return 0;
}
Exercise 6A - Wires, if-else The objective of this Exercise is to develop a program similar to the one in Exercise 5A, with the modification that a loop is used to process several flag values in one run of the program. Please review the problem description in the document for Exercise 5A. Write a program with a while loop to process several different flag values. For each flag value that is input, determine the appropriate wire color, printing out the appropriate message before requesting another input value.The decision on wire color is determined with if-else statements, so use the code developed in Exercise 5A. This program can be viewed as an enhancementmodification of Exercise 5A. You may read the values for the input flag from screen or file, as you choose. Be sure to test all options For submission, please use the following values, in this order: 55, 25, 5, 35, 40, 10 If the input is from screen, then part of the output should look something like the following. Please input a Ilag value: 55 You input a value of 55 The wire color is RED Please input a Tlag value: 25 You input a value of 25 The wire color is GREEN It is very easy to utilize the input prompt as a pseudo-echo for inputs Please input a Ilag value: 55 The wire color is RED Please input a flag value: 25 The wire color is GREEN In this case, the input request as in the example above (Please input a flag valuesrves as an identifier for en a class How will you terminate the loop? Do not set the loop to run for exactly 6 values. You will need to set up some sort of termination criteria. Some suggestions may be a flag value that is negative or a flag value of 999. Be sure to print something to the user to identify how the loop is to be terminated.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int flag;
cout << "Enter an Flag value(-1 to exit): ";
cin >> flag;
while(flag != -1) {
cout<<"You input a value of "<<flag<<endl;
if (flag >= 40)
printf("The Wire color is Red");
else if (flag >= 30 && flag <= 40)
printf("The Wire color is Blue");
else if (flag > 10 && flag < 30)
printf("The Wire color is Green");
else
printf("The Wire color is White");
cout<<endl << "Enter an Flag value(-1 to exit): ";
cin >> flag;
}
return 0;
}
Output: