Exercise 5b: #include \"stdafx.h\" #include <iostream> using namespace std; int
ID: 3587242 • Letter: E
Question
Exercise 5b:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int flag = 0;
cout << "input the value of flag";
cin >> flag;
switch (flag)
{
case 1:cout << " The wire is White";
break;
case 2:cout << " The wire is Green";
break;
case 3:cout << " The wire is Blue";
break;
default:cout << " The wire is Red";
break;
}
return 0;
}
Exercise 6B-VWir res, switc 1 The objective of this Exercise is to develop a program similar to the one in Exercise 5B, with the modification that a loop is used to process several flag values in one run of the program. The problem description is similar for the one in the document for Exercise 5B A circuit diagram requires wires of a certain color to be used in certain areas A tlag value is obtained from a blueprint or wiring diagram Using the flag value, determine the color of wire If flagExplanation / Answer
#include <iostream>
using namespace std;
int main()
{
int flag = 0;
cout << "input the value of flag (999 to exit) "<<endl;
cin >> flag;
while(flag < 1) {
cout<<"Input value is invalid"<<endl;
cout << "input the value of flag (999 to exit) "<<endl;
cin >> flag;
}
do {
while(flag < 1) {
cout<<"Input value is invalid"<<endl;
cout << "input the value of flag (999 to exit) "<<endl;
cin >> flag;
}
switch (flag)
{
case 1:cout << " The wire is White";
break;
case 2:cout << " The wire is Green";
break;
case 3:cout << " The wire is Blue";
break;
default:cout << " The wire is Red";
}
cout << "input the value of flag (999 to exit) "<<endl;
cin >> flag;
} while(flag != 999);
return 0;
}
Output: