I'm an absolute c++ beginner so please be patient.

#include <iostream>
using namespace std;

double array_of_5[5] = {1,2,3,4,5};
double sum(double a , double b );

double a= array_of_5[2];
double b= array_of_5[2];
int main ()
{
	
	cout<<"The sum of two members of the array is: " <<sum<< endl;

return 0;
}

double sum(double a, double b )
{
	return a + b;
}

I am trying to take the second term of the array and add it with the third term of this array
but when i debug this program only some random hexadecimal numbers (I guess) come out.
Please, if you could have a look at my code and tell me where I'm mistaking?
Thank you.

I don't get the memory location (I think that's what you mean)!

But:

#include <iostream>
using namespace std;

double array_of_5[5] = {1,2,3,4,5};
double sum(double a , double b );

double a= array_of_5[2];
double b= array_of_5[2];
int main ()
{
	
	cout<<"The sum of two members of the array is: " <<sum(a, b) << endl;

return 0;
}

double sum(double a, double b )
{
	return a + b;
}

You need to pass the values a and b for it to complete the calculation.

Hope this helps =)

Thank you. It didn't help very much but anyway, thanks for your reply. :)

The thing is it works kinda, but it prints out some numbers i'm not expecting.
( I tried to upload a pic of that what comes out but i failed).
Thanks again.

the second term of the array and add it with the third term of this array

you are taking the third item twice i.e 3+3

Ehh... i see that but anyway it's not printing 6 as it should, at least i expect to print that.
Thanks.

As I see it works with you and i guess you are using unix.
I'm working in visual studio 2010 professional.
If you could tell me how to upload a screen shot please.
Thank you very much.

OK. Thank you, it seems like the problem is not the way i wrote the code but the compiler. How can i check what kind of compiler I am using or is it good or whatever, please.

I am working on Visual Studio 2010 professional, windows 7 32bit.

You're using visual studio 2010 professional :P

Have you tried/heard of Dev-Cpp? It's really good for starting out =)!

Well this might sound very stupid but I just took the DVD the teacher gave me installed it and done. I didn't know that I have to install something else. :(

hahaha =)!

I hope your problem is resolved now (Remember, if you create more functions - Pass the variables through!)

If you thread is solved, please make it solved by clicking the "Mark this thread as solved" and give rep points if you think someone helped!

Goodluck :)

And you gave the most help. I'll try to give you that... reputation points. :)
thank you.

It was my mistake not the compiler or Visual Studio...
I called the function like this: cout<<"The sum of two members of the array is: " <<sum<< endl; and should have done it like this: ...<<sum(a,b)<<endl;

Yep! And I already thanked you for that.The reason why I posted here again is: I saw that people were viewing this thread and just wanted to make the mistake easier to find.

This question has already been answered. Start a new discussion instead.