Cannot print correct pattern, please help!!!

The question requires input the number of students then print the average and *
which is if i input 3 (student) 10 20 30(marks)
it should output
Number of students: 3
Student1: Student2: Student3:
Average:
**********
********************
*******************************

im ok with the first part but when it comes to printing stars, im stuck.

Heres my programme
#include <iostream>
#include <iomanip>
using namespace std;
#define n 20

int main() {
float mark[n];
int count;
float average=0;
cin >> count;
cout << "Number of students? " << count << endl;
for (int i=0; i<count; i++){
cin >> mark[n];
cout << "Student " << i+1 << ": " ;
average += mark[n]/count;}
cout << fixed << setprecision(2);
cout << "Average = " << average << endl;

for (int j=0; j<count; j++){
for (int z=0; z<mark[j]; z++){
cout << '*';}
cout << endl;
}
return 0;
}
it just print out 1 stars or infinitely many stars when i tried.
The problem is this:

1
2
3
cin >> mark[n];
...
average += mark[n]/count;}


Both should be i instead of n.
@coder777 thankssss thats what im looking for!!! I hv been debugging for hours.....
But i still dont understand, whats the difference between using mark[i] and mark[n]?
Why i must use mark[i]? I used mark[n] , it works for the 1st part of printing average but it stuck
When printing pattern thankssss
Also, for the 2nd for loop, if i type z<mark[z] instead of [j], it will print according to the
Count, im quite confused with the use of array ....
Last edited on
To understand arrays better take a look at this:

http://www.cplusplus.com/doc/tutorial/arrays/

Why i must use mark[i]?
n is the size of the array. It is always 20 and an invalid index. If you use it as an index it is out of bounds.

Also, for the 2nd for loop, if i type z<mark[z] instead of [j], it will print according to the
Count
Well, in that case z refers to the conent of a specific field of the array mark. So if you consider this:z<mark[z] z would be both the index of a field and the content of that indexed field which doesn't make sense.

By the way: average += mark[n]/count; is wrong. You need to divide by count after the loop is done.
Topic archived. No new replies allowed.