Hey guys I was wondering if you could provide some help, It is pretty complex for a person who is just starting loops. I have included the problem as well as the code I have below. Please help me, I know their is something wrong with my for loop as well as logic and other things. I have included part of the rounding function.
Write a program to find the largest, smallest, and average values in a collection of numbers where the value of num will be the first data item read.
Please make the following addtions:
1. The user will enter the value for "num" where "num" is the number of values in
the data set to be entered. Give the user 3 attempts at entering a value for
" num " where "num" is in the range from 0 to 20, inclusive. If the number "num"
entered is out of range, write an error message and continue. If the user
does not enter a valid value for "num" within the 3 attempts print an error
message and terminate the program.
2. Include the rounding function you wrote earlier to round the Average
value to 3 decimal places.
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
double roundIt(double x, double n) //Write definition for rounding function 3 decimal
{
x = floor( x * pow(100.0, n) + 0.5) / pow(100.0, n);
return x;
}
int main()
{
int listNo, num, ct, large, small, sum;
int att = 0;
cout << "Enter number of numbers that you want to see in a list" << endl;
cout << "that gives the average of. "
cin >> listNo;
do (att + 1)
while ((listNo < 0 && listNo > 20) && att < 3)
if( listNo >= 0 && listNo <= 20)
if ( listNo != 0)
{
cout << " Enter enter first value on list: " << endl;
cin >> num;
ct = listNo
large = num;
small = num;
sum = num;
for (listNo = 1; listNo < ct; listNo = listNo += 1)
{
cout << "Enter next value in list: " << endl;
cin >> num;
if ( x > large)
large = x;
if ( x < small)
{ small = x;
sum = sum + x; }
}
cout <<
system ("pause");
return 0;
}