hiddepolen 32 Posting Whiz in Training

so do I only need 1 input variable now (double d) for d because d is adding them in the sum method?

Look at the method. It is not just double d, but double...d, with three dots. This means you can put any amount of variables in there, even an array. Try it yourself.
Now you can use as many variables you want to sum up, and the same way is used to call the sum method in the average method.

hiddepolen 32 Posting Whiz in Training

You should except any number of variables as input in your method, like this:

public static double sum(double... numbers)
	{
		double add_num;
                for (double d: numbers)
		add_num += d;
		return add_num;
	}
public static double average(double... numbers)
	{
		double avg_num;
		avg_num = sum(numbers)/ numbers.length;
		return avg_num;
	}
}

Also read: http://www.java-tips.org/java-se-tips/java.lang/how-to-pass-unspecified-number-of-arguments-to-a-m.html

hiddepolen 32 Posting Whiz in Training

And, in the above, look at the doubles. First I print them with 0 precision, and the next one with 2 presicion.

(Output:

This is my int 'foo': 5, these are my doubles 'bar' and 'bar2': 7 and 3.93, and this is my 'ret' charachter : x

)

Cheers

hiddepolen 32 Posting Whiz in Training

I think what you're doing is correct, but:

Why dont you use 'printf ()'. This function is much handier, and lets you input everything you want (and print every way you want it).
Like this:

int main () {

int foo = 5;
double bar = 7.22, bar2 = 3.93;
char ret = 'x';

printf ("This is my int 'foo': %d, these are my doubles 'bar' and 'bar2': %.0f and %.2f, and this is my 'ret' charachter : %c", foo, bar, bar2, ret);


}

Try it!

Cheers

hiddepolen 32 Posting Whiz in Training

Strange. Could you post your entire code? Or at least all the relevant parts, everything to do with those two functions and the printing of the double.

Cheers

hiddepolen 32 Posting Whiz in Training

How do you know if it returns 7 or 7.00?
Do you print a double or an int?

When you convert the MyPrice return to an int, it'll become 7.

Post some more code?

hiddepolen 32 Posting Whiz in Training

Aah, So it's the sorting that nerds to shrink. OK let's see.
I think what you're doing is already quite effucient.

When I look at your code, you do the following:
Generate numbers,
Sort them,
Open the file,
Get the numers in your array,
Close the file.

Shouldnt the numbers in your file be sorted as well? Otherwise, it won't be likely you'll end up with a match.
Ill help you with the sorting tomorrow, I'm on my iPod right now, so it's impossible to code ;)

hiddepolen 32 Posting Whiz in Training

I like your idea for your program. Interesting concept !-)
My queston to you:
How do you want to compare them? (I mean 'in what way'). Like: is 5-17-2 equal to 17-5-2?

An idea for the numbers is:
Sort them first. Then, add them in one big integer. Like:
5-17-03 -> 051703. You can easily compare them to another number like 170503...
You can also use binaries, so it'll be even easier to shift with bits.

Good luck,
Cheers!

hiddepolen 32 Posting Whiz in Training

Hi Joseph, welcome to the forum?

I hope your problem is already solved, jsut one remark:
Can you use CODE tags, when typing code? They are in the top of your edit controls when editing a post.

It'll look like this:

for (int n = 0; n<max_size; m++) cout << n;
hiddepolen 32 Posting Whiz in Training

You could try to specify boudaries to the rand (), maybe that would help...

Try this:

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
	int x;
	x = rand() % 1500 + 1;
	cout << x;
	
	return 0;
}