2012-10-28, 09:08 PM
lol'd.
How slow are you going to not learn about arrays yet?
The way this program works is it assigns a value to prevNumber that is negative, this way it doesn't allow the user to input a digit to break its check. The check is done by checking if the input is the same as the previously assigned prevNumber. If it passes, it increments the total by one. If the number is less than 0, it breaks the loop and prints out the value. After both checks it assigns the prevNumber variable to a. cin.get() is there to pause the program for me.
How slow are you going to not learn about arrays yet?
Code:
#include <iostream>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
/*
"Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8".
Any value that is the same as the immediately preceding value is considered a CONSECUTIVE DUPLICATE.
In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6.
Note that the last 3 is not a consecutive duplicate because it was preceded by a 7.
*/
int main() {
unsigned int total = 0;
int a = 0;
int prevNumber = -1;
while(cin >> a) {
if(a == prevNumber)
++total;
if(a < 0)
break;
prevNumber = a;
}
cout << "Total Consecutive: " << total;
cin.get();
cin.get();
}The way this program works is it assigns a value to prevNumber that is negative, this way it doesn't allow the user to input a digit to break its check. The check is done by checking if the input is the same as the previously assigned prevNumber. If it passes, it increments the total by one. If the number is less than 0, it breaks the loop and prints out the value. After both checks it assigns the prevNumber variable to a. cin.get() is there to pause the program for me.

