Hi, all
i have the assignment about program which reads in integers from cin until the user enters a non-integer (a character or EOF), then print out the average.
Its pretty simple assignment but i am kind of new.
So the following is my code and seems like have some problems.
So is there anybody could point out it?? Thanks
int main()
{
int val=0,n=0;
int ave;
long int sum=0;
cout<<"please enter the first interger..."<<endl;
do
{
cin>>val;
if(!cin)
{
cin.clear();
cin.ignore(100);
cout<<"please enter an interger"<<endl;
}
else
{
sum+= val;
n++;
cout<<"please enter another interger..."<<endl;
}
}while(cin>>val);
ave = sum/n;
cout<<"the average is:"<<ave<<endl;
system("pause");
}