Why this program couldn't run the 'printArray' function. The program is running perfectly up to the function call. I hope you can help, thanks in advance!
#include <iostream>
using namespace std;
struct Point
{
char name[10];
int age;
};
void printArr(Point ar[])
{
for (int i = 0; i < sizeof(ar) / sizeof(ar[0]); i++)
{
cout << "Name of " << (i + 1) << " person: " << ar[i].name;
cout << "Age of " << (i + 1) << " person: " << ar[i].age;
}
}
int main()
{
struct Point p;
int n;
do
{
cout << "Enter n: ";
cin >> n;
if (n <= 0)
cout << "Ama ti si bil mnogo tup da vuvedesh n<=0\n";
} while (n <= 0);
struct Point ar[n];
for (int i = 0; i < sizeof(ar) / sizeof(ar[0]); i++)
{
cout << "Enter name of " << (i + 1) << " person: ";
cin >> ar[i].name;
cout << "Enter the age of " << (i + 1) << " person: ";
cin >> ar[i].age;
cout << "\n";
}
cout << "Now we have to run the 'printArr' function!\n";
printArr(ar);
return 0;
}