Its my beginners c++ assignment, I have a file of 12 columns of numbers and having 50 rows.
I am asked to find the average of the 11th column of the numbers and display it on the standard output.
Its a beginners class so NO advanced topics like vectors are allowed .
I was trying to make 12 variables for each coloumn and use the while loop to read the 11th coloumn but can't figure out how to add all the numbers of 11th coloumn into that variable.
The while loop I used was like this:
while(inputfile >> col1 >> col2>> col3>> col4>> col5>> col6>> col7>>
col8>> col9>> col10>> col11>> col12 )
{ cout<< col11 << endl; }
Side note : all the col above are int variables. And inputfile
is the ifstream
file object
The above loop would print out the whole coloumn 11 but I can't figure out how to add the whole coloumn 11 of 50 rows (i.e 50 numbers) to find the average(divide the total by 50)
The above method might be wrong too
Any help in this matter will be appreciated.
Hopeful of a response soon.
Thanks in advance. :)
Aucun commentaire:
Enregistrer un commentaire