Program to categorize inputs into bucket values

Okay so here is the assignment:
The program does the following:
1. first prompt the user to find out how many bucket values are there. You may assume there is
no more than 10 bucket values.
2. then read in all of the bucket values into an array. You may assume the bucket values are
strictly sorted from smallest to largest with no duplicates.
3. read in a lower bound and upper bound to describe valid range of input. You may assume
lowerBound <= upperBound
4. we will keep reading (and categorizing the value into different buckets) as long as the value
falls in between the range from step 3 [lowerBound, upperBound] inclusive.
5. print out how many values falls in each bucket.


Here is a sample input/output of the program:
v:\cmpsc101>lab14.exe
Enter number of bucket values:
2
Enter 2 bucket values:
0.5 1.5
Enter lower and upper bound of values to count:
-100
2.3
Enter values between -100 and 2.3:
-50
2.0
2.1
1.3
1.4
0.2
1.5
2.5
2 values are <= 0.5.
3 values are <= 1.5.
2 values are > 1.5.

and here is my code that will not work. please help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
using namespace std;
int getBucket(const double bucketvalues[], int size, double value);
int main()
{
	
	int values;
	double countarray[10];
	double valuesarray[10];
	int j=0;
	int x=0;
	int size;
	double lower;
	double upper;
	double bucketvalues[10];
	cout<<"Enter number of bucket values:\n";
	cin>>values;
	cout<<"Enter "<<values<<" bucket values:\n";
	for(int i=0; i<=values; i++)
	{
		cin>>bucketvalues[i];
	}
	cout<<"Enter lower and upper bound of values to count:\n";
	cin>>lower;
	cin>>upper;
	size=upper-lower;
	cout<<"Enter values between "<<lower<<" and "<<upper<<":\n";
	for(int i=lower; i<=upper; i++) {
		cin>>valuesarray[i];
		getBucket(bucketValues, size, i);
	
	}
	
	return 0;
}



int getBucket(const double bucketValues[], int size, int values) {
	int no=0;
	int j=0;
	for(int i=0; i<size-1; i++) {
		if (bucketValues[i] >= bucketValues[i+1])
		{
			no=1;
		}
	}
	
	if (no==0) 
	{
		while ((j<size))
		{
			if (values <= bucketValues[j])
			{
				return j;
			}
			j++;
		}
		if(values>=bucketValues[j]) {
		    return size;
		}
		
	}
	else if(no>0)
	{
	    
		return -1;
	}
		
}
Topic archived. No new replies allowed.