I have a home problem I'm working on. I and some other students are quite sure that our teacher made a reservation, but maybe not. I already checked a few questions here and can't find a way to use pointers to create what is essentially an array. Instructions are read as follows.
- Rewrite the following program to use pointers instead of arrays:
Code is
int main()
{
int salary[20];
int i;
for (i = 0; i < 20; i++)
{
cout << "Enter Salary: ";
cin >> salary[i];
}
for (i = 0; i < 20; ++i)
salary[i] = salary[i] + salary[i] / (i + 1);
return 0;
}
My solution was as follows:
int main()
{
int* salary_pointer = new int;
for (int i = 0; i < 20; i++)
{
cout << "Enter Salary: ";
cin >> *(salary_pointer + i);
}
for (int i = 0; i < 20; ++i)
{
*(salary_pointer + i) = *(salary_pointer + i) + *(salary_pointer + i) / (i + 1);
cout << *(salary_pointer + i) << endl;
}
delete salary_pointer;
return 0;
}
He continues to report a segmentation error of approximately salary number 13
( , ) , , . !