Problem With Code

Please help me with the following code in c++ I'm getting errors with my code

Problem 1: Find unique numbers

Write a program to accomplish the following:
Prompt user for an integer number n (ensure n<20) followed by n integers, each having a value between 0 and 50. Find and display unique values among the input numbers and frequencies of these unique numbers. (Hint: Use an array for storing n input numbers. Use another array to help count frequencies of unique numbers.)

Sample input: Enter n: 6

4 4 3 1 1 4

Sample output:

Number 1: 2

Number 3: 1

Number 4: 3




Code:


#include <iostream.h>
#include <conio.h>
int main()
{
int arr[50], freq[50];
int n, i, j, count;
clrscr();
cout<<"Enter n: ";
cin>>n;
while(n>19)
{
cout<<"enter size less than 20";
cin>>n;
}
cout<<"Enter elements in array: ";
for(i=0; i<n; i++)
{
cin>>arr[i];
while(arr[i]>50 || arr[i]< 0)
{
cout<<"number between 0 to 50";
cin>>arr[i];
}
freq[i] = -1;
}
// Counts frequency of each element
for(i=0; i<n; i++)
{
count = 1;
for(j=i+1; j<n; j++)
{
if(arr[i]==arr[j])
{
count++;
freq[j] = 0;
}
}

if(freq[i]!=0)
{
freq[i] = count;
}
}

// display results
cout<<"\nFrequency of all elements of array : \n";
for(i=0; i<n; i++)
{
if(freq[i]!=0)
{
cout<<"number\t"<<arr[i]<<"\t :"<<freq[i]<<" times\n";
}
}
getch();
return 0;
}

what exactly is the error?

is it
 fatal error: iostream.h: No such file or directory

if yes then you are testing your c++98 program on a modern compiler

iostream.h, getch(), and all stuffs like that are discontinued...

hope it helps

ps: please use code tags
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.