The user will enter the value for "n" where "n" is the number of values in the data set to be entered. Give the user 3 attempts at entering a value for " n " where "n" is in the range from 0 to 20, inclusive. If the number "n" entered is out of range, write an error message and continue. If the user does not enter a valid value for "n" within the 3 attempts print an error message and terminate the program.
Include the rounding function to round the Average value to 3 decimal places.
The n values entered for input can be positive, negative, or zero. But what about the n value? Use data validation to validate n.
I put the directions in here only so you know what I am ultimately after.
My problem is that I am supposed to be setting up a for loop within the program after my do-while loop. I am not sure how to set up a for loop.
int main()
{
double n; // input - 1st value entered by user
int count; //
double averageNumber; // output - average, with 3 decimal
double largeNumber; // output - largest value of the 3 entered
double smallNumber; // output - smallest value of the 3 entered
instruct();
//Enter 3 values for n within a range of 0 - 20.
count = 0;
do
{
count + 1;
cout << "Enter a value for n within a range of 0 - 20: "; cin >> n;
cout << endl << endl;
} while (!(n >= 0 && n <= 20) && count < 3);
if (n >= 0 && n <= 20);
elseif (n == 0);
cout << " The number is valid but cant get data set from 0" << endl;
//Determine which value entered is highest, lowest, and the average of the 3
//pseudo code
{
var = start value
while( condition ) {
loop body
do something //a single statement, i.e. one line ending with a ;
}
} //var is out of scope here
//--------------------------------------------------------------------------------
//example in C++
{
int i = 1;
while( i <= 10 ) {
//loop body
double num;
cout << "Enter a number: ";
cin >> num;
cout << i << ". " << num;
//increment i so it will be greater then 10 after 10 iterations
i++;
}
}
With a for loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//pseudo code
for( var = start value; condition; do something ) {
loop body
} //var is out of scope here
//--------------------------------------------------------------------------------
//example in C++
for( int i = 1; i <= 10; i++ ) {
//loop body
double num;
cout << "Enter a number: ";
cin >> num;
cout << i << ". " << num;
}