Thread: Please help me

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    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

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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. Why it can't read in a number?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed