I am not sure what I am doing. I need this thing to keep running the loop but it will only ask for input once when I run it. What do I need to change and/or add? Also, the last statement will not display? I need it to show up when the loop stops. My teacher doesn't want us to set the loop to run a specific number of times. she said set up some sort of termination criteria. The instructions are vague. I'll post them after the code too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
using namespace std;
int main()
{
int input;
int count;
int num;
int sentinel = 999;
cout << "Exercise 6A" << endl;
cout << "Kaitlin N. Stevers" << endl;
cout << "September 25, 2016" << endl;
cout << "\t\t" << endl;
cout << "\t\t" << endl;
cout << "Please input value: \n" << endl;
cin >> num;
cin.get();
while (input != sentinel)
{
if (num < 10)
{
cout << "The wire is: White" << endl;
}
else
if (num < 30)
{
cout << "The wire is: Green" << endl;
}
else
if (num < 40)
{
cout << "The wire is: Blue" << endl;
}
else
{
cout << "The wire is: Red" << endl;
break;
}
cout << "Have a great day & thank you for yousing Katie's program!" << endl;
return 0;
}
|
Here are the instructions:
EGR 126
Updated 8/20/2016
Exercise 6A – Wires, if-else
The objective of this Exercise is to develop a program similar to the one in Exercise 5A, with the alteration 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
enhancement/modification of Exercise 5A.
You may read the values for the input flag from screen or file, as you choose.
Please use the following values, in this order: 55, 25, 5, 35, 40, 10
If input from screen, then part of the output may look something like the following:
Please input a flag value: 55
You input a value of 55
The wire color is RED
Please input a flag 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 flag 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 value: ) serves as an
identifier for the input value. This is not good programming practice, and this technique should not be used for
Assignments in this 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.
** The other instructions just let us know the if statements which are in my code.
-----Thanks to everyone who helped me and tried to help me :) ----