Hi,
I'm pretty much new at C++ and we've begun discussing for-loops in class today. We were given a problem for homework:
Write a program that reads a collection of positive and negative numbers and multiplies only the positive integers. Loop exit should occur when three consecutive negative values are read.
I'm not sure how to use the sentinel function to end when three consecutive negative values are entered. As far as I can suspect, the code should go something like this?:
That's all I can really figure out right now, any help would be greatly appreciated.Code:. . . for (cin >> number; number != SENTINEL; cin >> number) { if (number > 0) number *= number; . . .



LinkBack URL
About LinkBacks




