-
Please help me
#include"../../std_lib_facilities.h"
int main(){
vector<double>myval;
double numb;
double smallest=0.0,largest=0.0;
double total_distance=0.0;
cout<<"Please Enter the Values:\n";
while(cin>>numb)
{
myval.push_back(numb);
}
for(int i=0;i<myval.size();i++)
{
total_distance=total_distance+myval[i];
if(myval[i]<=smallest)
smallest=myval[i];
else if(myval[i]>=largest)
largest=myval[i];
cout<<myval[i]<<"\n";
}
keep_window_open();
}
The Program Gets Teriminated if we give any character.but it should come out of the loop rather than terminating.
While it is terminated .The program exits .Please help me
-
-
If you cin into a number and type something (like a letter) that cin can't figure out how to convert into a number, it will fail, leaving the variable you were reading into untouched and cin in a fail state.
See e.g. http://cboard.cprogramming.com/cplus...ad-number.html