H
hpy_awad
I know that group is for C not for C++ but please try to help me ,
How can I declare size of an array as variable value came from screen?
#include "iostream.h"
#include "iomanip.h"
#include "conio.h"
float ArraySum(float Array[],int ArraySize);
int main()
{
clrscr();
int ArraySize=0;
// Read the array elements
cout << "Enter Array Size : " ;
cin >> ArraySize;
^^^^^^^^^^^^^^^^^^^^^
float Array[ArraySize];
^^^^^^^^^^^^^^^^^^^^^^^
cout <<endl<< "Enter Array Elements " ;
for (int i=0;i<=ArraySize;i++)
{
cout <<endl<< "Enter elements no " << i << " : ";
cin >> Array;
}
cout <<endl << "The sum of the elements values :" << setw(5) <<
ArraySum(Array,ArraySize);
return 0;
}
float ArraySum(float arr[],int n)
{
int total=0;
for (int i=0;i<=n;i++)
total+=arr;
return total;
}
How can I declare size of an array as variable value came from screen?
#include "iostream.h"
#include "iomanip.h"
#include "conio.h"
float ArraySum(float Array[],int ArraySize);
int main()
{
clrscr();
int ArraySize=0;
// Read the array elements
cout << "Enter Array Size : " ;
cin >> ArraySize;
^^^^^^^^^^^^^^^^^^^^^
float Array[ArraySize];
^^^^^^^^^^^^^^^^^^^^^^^
cout <<endl<< "Enter Array Elements " ;
for (int i=0;i<=ArraySize;i++)
{
cout <<endl<< "Enter elements no " << i << " : ";
cin >> Array;
}
cout <<endl << "The sum of the elements values :" << setw(5) <<
ArraySum(Array,ArraySize);
return 0;
}
float ArraySum(float arr[],int n)
{
int total=0;
for (int i=0;i<=n;i++)
total+=arr;
return total;
}