I'm just a second year college student in Computer Science so please be nice..:)

I have this course requirement where we were asked to make a program about any hashing technique. I chose Division because it's easier.

Anyways, I'm having a hard time in getting the "highest prime number". When I just use the inputed File Size, the output always show the hashed address of the second inputed number..

#include<iostream.h>

void main() {
	int N, i,h, b, HP, r, l,  m;

	cout<<"Enter File Size: "; cin>>N;
	cout<<endl;

	if((N%2)==1) {
		cout<<"Highest Prime Number: "<<N;
	}

	cout<<endl;

	cout<<"Enter number of inputs: "; cin>>h;
	for(i=1; i<=h; i++) {
		cout<<"Enter numbers: "; cin>>b;
	}

	cout<<"Hashed Addresses: "<<endl;
	for(r=1; r<=h; r++) {
		HP = b / N;
		l=HP*N;
		m=b-l;
		cout<<m<<endl;
	}
	cout<<endl;
}

please help me...:'(

this loop

for(i=1; i<=h; i++) {
		cout<<"Enter numbers: "; cin>>b;
	}

is overwrites b, so here

for(r=1; r<=h; r++) {
		HP = b / N;
		l=HP*N;
		m=b-l;
		cout<<m<<endl;
	}

you've got the last b value.

maybe you better put values in int array, not in int variable?

like this:

int b [h];
int current_b_index = 0;

while ( current_b_index < h )
{
cout << "Enter numbers: "; 
cin >> b[current_b_index++];
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.