Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created February 1, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanfal/058762e174865885a087 to your computer and use it in GitHub Desktop.
Save juanfal/058762e174865885a087 to your computer and use it in GitHub Desktop.
trying to solve a problem
// Make a subprogram void freqNumbers(int freqs[], int min, int max)to read
// numbers between min and max, until a number out of this range is entered.
// Then, the subprogram must return the frequencies of every number, and then
// in the main() print on the screen every number with its frequency. Try it
// with 0 and 9 for min and max. For example:
// Input: 1 8 7 3 4 8 5 9 5 0 0 4 8 4 5 3 2 8 -1
// Output: 0:2; 1:1; 2:1; 3:2; 4:3; 5:3; 6:0; 7:1; 8:4; 9:1
#include <iostream>
using namespace std;
void freqNumbers (int freqs[], int min, int max)
{
// Okey , my problem is here. I managed to do an algorythm that creates an
// array with a not given dimension, so it depends on the number of
// numbers that the user enters.
// The problem is that i dont know the way to make the subprogram
// freqNumbers know the size of freqs[] array.
}
int main()
{
int min = 0;
int max = 9;
int x;
int i = 0;
int freqs[i];
cout << "Introduce numbers between 0 and 9, or a number"
" out of range, so the program ends:" << endl;
cin >> x;
while (x > min && x < max) {
freqs[i] = x;
++i;
cin >> x;
}
for (int j = 0; j < i; j++) {
cout << freqs[j];
}
freqNumbers(freqs, min, max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment