Several errors with writing this reverse and increment function

I've been working on trying to figure out these functions for too long without any advice. Can anyone help guide me through how to fix these functions? I'm having troubles figuring out how to declare number in the scope.....how to write out the actual function...and how to output the results from the functions. Here's what I have:

void increment(double array[], int size, double number);
//This function receives an arrya, array's size, and a number.
//The function adds the number to each element of the array.

void reverse(double array[], int size);
//This funciton receives an array and its size.
//The function reverses the order of all elements in the array.
//For example, if array=[6,2,5,3,4], the funciton changes it to array=[4,3,5,2,6].
.
.
.
.
.
.
//Add 0.2 to each GPA
increment(GPA,size,number);

//Print the updated GPA list
cout<<"GPA list after adding 0.2 to each GPA."<<endl;


//Reverse the GPA list.
reverse(GPA, size);

//Output the reversed list.
cout<<"GPA list after reversing"<< endl;
.
.
.
.
.
//--------------------------------------------------------------------------------
void increment (double array [], int size, double number)
{

for (int i=0; i<=size; i++)
{
array [i]=array [i]+size+0.2;
}
}
//--------------------------------------------------------------------------------
void reverse (double array[], int size)
{
for (int i=0; i <= size; i++)
{
swap( array[i], array[0]);
}
}
.
.
.
.
.


Last edited on
It'd help if you actually told us what symptoms you were experiencing.

However, For your reverse function. You want something more like:
1
2
3
for (int i = 0; i < size/2; ++i) {
 swap(array[i], array[size - (1 + i)];
}
Well no errors are being shown when I g++, so there's no real guidance there on what I need to fix. So really all that I can say about my problems is that I know I must be doing it wrong because my increment function does not involve "number" in it's function. And for the output of the code, I just don't know where to start. I thought that maybe printing out the increment could look something like this

"print (GPA, size, number);"

But since I don't have the equation right, I can't test it :/
What you should be doing is outputing the values you're getting; and then saying "these don't match what I expect." Then coming on here and saying "Well I get X; but I expect Y and I'm not sure what is happening".

You've come here and said; "Well it doesn't work; I'm not going to give you any hints as to why; or what It's giving me; or what I expect". You need to help us; so we can help you.

Looking at your increment code.
1
2
3
for (int i = 0; i < size; ++i) {
 array[i] += number;
}

Should be sufficient.
Topic archived. No new replies allowed.