this is the Qustion:
Write C++ program that contains two functions: main and a function named "reverse". You should initialize an array of floating point values in the main and print it then send it to the function “reverse” that takes as its arguments the following:
(1) an array of floating point values;
(2) an integer that tells how many floating point values are in the array.
The function must reverse the order of the values in the array. Thus, for example, if the array that's passed to the function looks like this:
0 1 2 3 4
5.8 | 2.6 | 9.0 | 3.4 | 7.1
then when the function returns, the array will have been modified so that it looks like this:
0 1 2 3 4
7.1 | 3.4 | 9.0 | 2.6 | 5.8
The function should not return any value. Finally you should print the reversed array in the main.
and this is my code there is somrthing wrong with the output but i didn't know where it is, really need 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
|
include<iostream>
using namespace std;
float reverse(float a[]);
int main()
{
int n;
float x[5];
cout<<"please enter the range of array: "<<endl;
for(int i=0;i<5;i++)
{
cout<<"please enter a float number :"<<endl;
cin>>x[i];
}
float reverse(x[5]);
}
float reverse(float a[5])
{
float y[5]={0.0};
for( int i=0;i<5;i++)
{
y[i]=a[i];
}
for(int i=4;i<=0;i--)
cout<<y[i];
cout<<"the number of the numbers is"<<5;
return 0;
}
|