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 do not want the code written for me i just want some help.
I'm not sure how to use the sentinel function to end when the three consecutive negative values are entered.
I did the code below as a start but i dont know if its relevant. Is it?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include<iostream>
usingnamespace std;
int main()
{
int i;
for(i=0;i<5;i++)
{
cout<<i<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Also should the numbers be randomly generated so there is variation in numbers?
Any input is appreciated. Thanks
As it is said in your assignment the program have to read a collection. That is I think you should use standard input stream std::cin to read integers until three consecutive negative integers will be encountered. So you need a count of negative numbers in the loop.
#include<iostream>
usingnamespace std;
int main()
{
int number;
int positive=0;
int negative=0;
//Read the Data
double average;
cout <<" Enter first Number : ";
cin >> number;
while (number != 0)
{
if (number > 0)
positive++;
else
negative++;
cout <<" Enter second Number : " ;
cin >> number;
cout << endl;
cout <<" there are "<<positive<<" Positives "<<endl;
cout <<" there are "<<negative<<" Negatives " << endl;
cout <<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
}