My program doesn't work .

This program is design to compute the number of occurrences for each number in the list .
This is the code .

#include <iostream>
#include <cstdlib>

using namespace std;

int rand_int(int a, int b);

void main (void){

int low, high, i,vect[50],c,d=0,B[50],q,j,A[50];
cout << "Plese provide the low and high values:\n";
cin >> low;
cin >> high;
cout<< "The random numbers between " << low << " and " << high << " are: \n";

for(j=0;j<50;j++)
{

c=rand_int(low, high);

cout<<c<<"\t";
A[j]=c;
}

cout<<"No-\t\t\t Repetations\n";


for(i=low;i<=high;i++)
{

for(j=0;j<50;j++)
{

if(A[j]=i)

d++;

}
q=i-low;
B[q]=d;

cout<<" "<<A[j]<<"\t\t\t"<<d<<"\n";

d=0;
}
getchar();
getchar();
}

int rand_int(int a, int b){
int j;
j=rand()%b;
while(j>a)
j=rand()%b;
return j;}







Last edited on
I have not analyzed the logic in your program, but two things jump out immediately:

1) if( A[j] = i ) is the assignment operator, not the comparison operator.

2) rand_int() while( j > a ) is not what you meant. This keeps trying until it returns a number that is not > a, right?

Next time please use code tags when posting your code. (Use the # symbol in the list to the right).
I want it works Just as in this image.

http://www.2shared.com/fadmin/4394306/2837e29/ppP-008.jpg
Last edited on
This discussion seems to be the same as this
http://www.cplusplus.com/forum/beginner/6123/ ...
Topic archived. No new replies allowed.