Stuck on a C++ code problem

free
Last edited on
[code] "Please use code tags" [/code]

Keep console open http://www.cplusplus.com/forum/articles/7312/
Why system is evil http://www.cplusplus.com/forum/articles/11153/

Average \bar{x} = \frac{ \sum_1^n x_i }{ n } (sum all elements, divide for the number of elements)

There is no difference between writing to files or to the console (they are both streams)
1
2
3
4
5
6
7
8
9
for (int x = 0; x < 10; x = x + 1)
{
  cout << height[x] << endl;
}
//...
for (int count = 0; count < 10; count = count + 1)
{
  studentHeights << height << endl; //you are writing a pointer here
}
Last edited on
In your FOR loop, instead of writing out "x = x + 1" or "count = count + 1", use "x++" or "count++".
Problem 1)How much data are you able to write to "height.txt"?
Problem 2)After cin>>height[x] you can calculate the average height by summing the ten elements in this array and dividing by 10 using a loop..... or add the sum code and division by 10 within this loop block.e.g.
1
2
3
4
5
6
7
8
cout << "The student heights you entered are: "<< endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << height[x] << endl;
sum_of_heights+=height[x];
av_stud_height=sum_of_heights/10;
cout<<av_stud_heights<<endl;
}
Topic archived. No new replies allowed.