What the wrong on program c++ !!!

hi every one i need now to know the wrong on this program pLZ


write a program that defines the following function:
.int ReadDate (int[]x)
read from the user an integer N follwed by N integers.the N integer will be saved in the parameter array x.the function returns the number of data items being read ,i.e .N
void printData (int[]x,int N)
prints the first N integers in array x .the items should be printed on the same line ,separated by ',' and with a fullstop '.' at the end ,followed by a new line.
bool allpositive (int []x,int N)
this function return true if all N integers in x are positive.
bool allsorted(int [] x, int N)
this function return true if all n integer in x are sorted in an ascending (nondecreasing) order.
void computeSum(int[], int [], int N)
this function will set elements in array y such that the value of y[k] (k=0..N)is equal to the sum of all items from x[0] to x[k] (inclusive.)
the main program will call ReadData to get the data from the user,and then it will print the following information:

1.print the data using printData.
2.print if the data is sorted or not.
3.print if the data is all positive or not.
4.call computeSum and prints the resulting array.
you assume tht the user will not enter more than 100 integers.
study the following sample input /output . the text in bool is typed by the user while the regular text is printed by the program.
I need data : 5 -4 12 16 36 42
Data is: -4 , 12, 16 36, 42.
The data IS sorted.
The Data IS NOT all positive .
Data Sum is: -4,8 ,24 ,60 ,102.
Thank you.



__________________________________________________________________

that mu Sol :

#include <iostream>
using namespace std;

int readdata (int x [] )
{
int N;
cin >> N;
for ( int i=0 ; i<N ; i++){
cin >> x[i];
}
return N;
}





void printData (int x [] , int N){
for ( int i=0; i<N-1 ; i++ ){
cout << x [i] << ',' << ' ' ;
}
cout << x [N-1] << '.' << endl;
}





bool allPositive (int x[] , int N){
for(int i=0 ;i<N ;i++){
if(x[i]<=0)
return false;
}
return true ;
}



bool allstored ( int x[] , int N ) {
for(int i=0 ;i<N ;i++){
int m=i;
for ( int j=0 ; j<N ; j++){
if ( x[j]>x[m]){
m=j;
return false;
}
return true ;
}

}
void ComputeSum(int x[],int y[] ,int N){
int count=0;
cout << " Data Sum is :";
for(i=0;i<N;i++)
{
y[count]=y[count]+x[i];
cout << y[count] ;
if(i<n-1)
{
cout << ", ";
}
}
cout <<" .";
}




int main (){
int N;
int x[100];
cout << " I need data :";
int n = readdata(x);
cout << " Data is :";
printData (x,n);
if ( allstored){
cout << " The Data is stored ";
}
else
}
else
{
cout << "The data IS not sorted ";
if (allPositive){
cout <<" Data is Not all positive . ";
}
else
{
cout << "The Data all positive ";
}
ComputeSum ( x, y , n ){
cout << " THANK YOU ";

system ("pause");
return 0;
}


i hope to get the sol before 12 night today : )
The array are not dynamic, this means the size of the array could not be decided on the execution times
you should consider vector of c++
Can you correct the code for me ?


i do not have time to think
Last edited on
[code] "Your code goes here" [/code]
Your array is over-sized (another method to deal with unknow size at compilation)

void ComputeSum(int x[],int y[] ,int N) Why do you ask for an array if you just use the first cell?

What is the problem?
Topic archived. No new replies allowed.