Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Where's the input query in this code??

UlnarianUlnarian Posts: 13Member
Hey all, I'm kinda new at this whole programming thing. Anyways, I've got this book, and the following is a chunk of code from the book. Apparently, somewhere in here, this program asks the user to input the weight of his fish, but....I can't find it....can you tell me where its at?

Here's the relevant portion:


double fish[Max];
cout << "Enter weight.
";
cout << "You may enter up to " << Max
<< " fish <q to terminate>.
";
cout << "fish #1 ";
int i=0;
while (i<Max && cin >> fish[i]) {
if (++i < Max)
cout << "fish #" << i+1 << ": ";
}


Does the test condition portion of the while loop double as an input query from the user??

Comments

  • DonotaloDonotalo Posts: 715Member
    : Hey all, I'm kinda new at this whole programming thing. Anyways, I've got this book, and the following is a chunk of code from the book. Apparently, somewhere in here, this program asks the user to input the weight of his fish, but....I can't find it....can you tell me where its at?
    :
    : Here's the relevant portion:
    :
    :
    : double fish[Max];
    : cout << "Enter weight.
    ";
    : cout << "You may enter up to " << Max
    : << " fish <q to terminate>.
    ";
    : cout << "fish #1 ";
    : int i=0;
    : while (i<Max && [red]cin >> fish[leftbr]i[rightbr][/red]) {
    : if (++i < Max)
    : cout << "fish #" << i+1 << ": ";
    : }
    :
    :
    : Does the test condition portion of the while loop double as an input query from the user??
    :
    [purple]look at the [blue]while[/blue] condition, there is a [blue]cin[/blue] statement which is taking the input.
    [/purple]
    [hr][purple]~Donotalo()[/purple]

  • UlnarianUlnarian Posts: 13Member
    Thanks, I just didn't know that the expression test portion of a while loop could also double as an input query :)


    : : Hey all, I'm kinda new at this whole programming thing. Anyways, I've got this book, and the following is a chunk of code from the book. Apparently, somewhere in here, this program asks the user to input the weight of his fish, but....I can't find it....can you tell me where its at?
    : :
    : : Here's the relevant portion:
    : :
    : :
    : : double fish[Max];
    : : cout << "Enter weight.
    ";
    : : cout << "You may enter up to " << Max
    : : << " fish <q to terminate>.
    ";
    : : cout << "fish #1 ";
    : : int i=0;
    : : while (i<Max && [red]cin >> fish[leftbr]i[rightbr][/red]) {
    : : if (++i < Max)
    : : cout << "fish #" << i+1 << ": ";
    : : }
    : :
    : :
    : : Does the test condition portion of the while loop double as an input query from the user??
    : :
    : [purple]look at the [blue]while[/blue] condition, there is a [blue]cin[/blue] statement which is taking the input.
    : [/purple]
    : [hr][purple]~Donotalo()[/purple]
    :
    :

Sign In or Register to comment.