### How to write a data loop?

I need to write a data input for one of my class assignment.
Would this be considered a data loop?

while (cin >> number)

If not would someone post an example of one.
Thank You.
I am not completely sure what you want, but from the looks of it, it seems you are learning about loops in general. I suggest you take a look at this http://www.cplusplus.com/doc/tutorial/control/. This should help you learn more about loops, but to be more exact, skip to the While Loop section and check out the example code there. It is pretty close to what you are probably looking for, so that should help.

Last edited on
The link that you posted is broken.
My assignment requires me count the number of user inputs and some calculations. The only problem I have is starting it up. It is supposed to look like this

Enter values: 54.53 94.18 66.4 66.5 done
[4 values, average=70.40, standard deviation=16.82]
I fixed the link, but I think you are going to need a few more things then just a loop. What code do you have so far?
This is what I have so far
int run(istream& cin, ostream& cout)
{
// Variables
double value;
int count = 0;
double average;
double mean;
//mean = 0;
average = 0;
string s;

// Inputs
cout << "Enter values: ";
//cin >> value;
//cout << "[";
while (cin >> value >> s)
{
average = (average + value) / count;
//mean = average / count;
cout << average;
if (s == "done")
return 0;
else
count++;
}

cout << "[" << " values," << average << "average=" << ","
<< "standard deviation=" << "]";

return 0;
}

I don't know how to count the users input.
Last edited on
Topic archived. No new replies allowed.