It has been a while since i have taken C++ and I am tryig to write a program. The program is supposed to let the user input how many vertices the polygon will have, then let them put in the vertices, calculate the length of the sides, then use Heron's formula to determine the area. I know to start the program i should ask the user how many vertices the polygon will have, then i have to use a loop and arrays to enter the data. However i am not quite sure on how to begin writing this. Can anyone give me help on using loops with arrays?

However i am not quite sure on how to begin writing this. Can anyone give me help on using loops with arrays?

#include <iostream>
 
 int main(void)
 {
    int size;
    std::cout << "size? ";
    std::cin  >> size;
    int *array = new int[size];
    for(int i = 0; i < size; ++i)
    {
 	  std::cout << "array[" << i << "]? ";
 	  std::cin  >> array[i];
    }
    std::cout << "array[" << size << "]: ";
    for(int i = 0; i < size; ++i)
    {
 	  std::cout << array[i] << ' ';
    }
    std::cout << std::endl;
    delete[] array;
    return 0;
 }
 
 /* my output
 size? 4
 array[0]? 1
 array[1]? 2
 array[2]? 3
 array[3]? 5
 array[4]: 1 2 3 5
 */
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.