C
curiousEngine
a program that reads in a sequence of positive integers and prints out
the
longest streak of the same value. eg:
2 6 4 3 3 2 3 2 2 2 2 6 6 6 1 6 6 6
Streak of 4 2's in a row.
int main(){
int inputInteger, prevInteger, streak(1), streakInteger;
cout << "Enter positive integers (end by negative integer) "<<endl;
do{
cin >> inputInteger;
if (prevInteger == inputInteger){
streak++;
streakInteger = inputInteger;
}
prevInteger = inputInteger;
}while(inputInteger > 0);
cout << streak<<"of"<<streakInteger;
How to determine the longest streak???
the
longest streak of the same value. eg:
2 6 4 3 3 2 3 2 2 2 2 6 6 6 1 6 6 6
Streak of 4 2's in a row.
int main(){
int inputInteger, prevInteger, streak(1), streakInteger;
cout << "Enter positive integers (end by negative integer) "<<endl;
do{
cin >> inputInteger;
if (prevInteger == inputInteger){
streak++;
streakInteger = inputInteger;
}
prevInteger = inputInteger;
}while(inputInteger > 0);
cout << streak<<"of"<<streakInteger;
How to determine the longest streak???