Hello all
I was looking into some textbook solution (preparing for my exam)
and I saw this program:
Question Details:
write a program that reads in a set of positive integers, representing test scores for a class, and outputs how many times a particular number appears in the list. you may assume that the data set has at most 100 numbers and -999 marks the end of the output data. the numbers must be output in increasing order. for example, for the data:
55 80 78 92 95 55 78 53 92 65 78 95 85 92 85 95 95
the output is:
test score count
53 1
55 2
65 1
78 3
80 1
85 2
#include<iostream>
using namespace std;
int main()
{
int numbers[101]={0},i,num;
cout<<"enter a number: ";
cin>>num;
while(num!=-999)
{
numbers[num]++;
//cout<<numbers[num]<<" "<<endl; >>this appears to be a counter
cout<<"enter a number: ";
cin>>num;
}
cout<<"test score\tcount\n";
for(i=0;i<101;i++)
if(numbers[i]!=0)
cout<<i<<"\t\t"<<numbers[i]<<endl;
system("pause");
return 0;
}
how does it work ?
what does "i" represent ?