0

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?

2
Contributors
1
Reply
3
Views
13 Years
Discussion Span
Last Post by Dave Sinkula
0

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
 */
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.