Where's the input query in this code?? - Programmers Heaven

Howdy, Stranger!

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

Categories

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.