0

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...:'(

2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by cerf_machine
0

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++];
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.