Trying to print all the adjacent duplicates of an input

I want all adjacent duplicates. Like, if the input is 1 3 3 4 5 5 6 6 2, the program should print 3 5 6. I've tried moving stuff around but I can't get the output I want. Not sure if I'm missing something or my logic is wrong. Thanks in advance. :)

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double input;
double previous;
cout << "Please enter a series of numbers : ";
cin >> previous;
while (cin >> input)
{
if (input == previous)
{
input ++;
}
cout << "The duplicate inputs are: "<< input << endl;
previous = input;
}

}
Read this please
http://www.cplusplus.com/articles/z13hAqkS/


something like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;


int main()
{

	int i = 0;
	int arr[100];
	int size;

	cout << "How many numbers would you like to enter ";
	cin >> size;
	cin.ignore();

	for (i = 0; i < size; i++)
	{
		cout << "Enter a number ";
		cin >> arr[i];
		cin.ignore();
		cout << endl;
	}
	

	for (i = 0; i < size - 1; i++)
	{
		if (arr[i] == arr[i + 1])
			cout << "Duplicate number " << arr[i] << endl;
	}
	cin.ignore();
	return 0;
}
That works, thanks. :)

Is there a way to do this without an array though? I'm trying to stay in context of my class' subject material. Is my logic just completely off?
You dont get the same result of duplicates if you enter 12123434
You mean the duplicates have to be adjacent? Yea, I know that much. Part of my assignment is that they have to be adjacent.
Ahhh adjacent
I did not pay more attention to that
apologies
No big :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cmath>
using namespace std;
int main() 
{
	double input = 0;
	double previous;
	cout << "Please enter a series of numbers ending with -1: "; 
	cin >> previous;
	cin.ignore();

	cout << "The duplicates are ";
	while (input != -1)
	{		
		cin >> input;
		cin.ignore();
		if (input == previous) 
		{ 
			cout << input << ",";
		}
		previous = input;
		
	}
	cin.ignore();
	return 0;
} 
Last edited on
Topic archived. No new replies allowed.