-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode.cpp
More file actions
52 lines (46 loc) · 968 Bytes
/
Copy pathmode.cpp
File metadata and controls
52 lines (46 loc) · 968 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <vector>
void mode(std::vector<double> & v)
{
int counter = 0;
int mode = 0;
for(unsigned int i = 0; i < v.size();i++)
{
int temp = v[i];
int temp_count = 0;
for(unsigned int j = 0; j < v.size();j++)
{
if(temp == v[j])
{
temp_count++;
}
}
if(temp_count > counter)
{
counter = temp_count;
mode = temp;
}
}
std::cout << "Mode is " << mode << " amount " << counter << std::endl;
}
void print(const std::vector<double> & v)
{
for(unsigned int i = 0; i < v.size();i++)
{
std::cout << v[i] << "\n";
}
}
int main()
{
double temp = 0.0;
std::vector <double> numbers;
std::cout << "This program will find the mode of a sequence of numbers"
<<" After entering the sequence enter a symbol that is not a number" << "\n";
while(std::cin >> temp)
{
numbers.push_back(temp);
}
mode(numbers);
print(numbers);
return 0;
}