#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
   const int LENGTH = 100;
   double prices[LENGTH];

   int number_of_prices = 0;
   double price;
   while (cin >> price)
   {
      if (number_of_prices < LENGTH)
      {
         prices[number_of_prices] = price;
         number_of_prices++;
      }
   }

   double sum = 0.0;

   if (number_of_prices >= 2)
   {
       sum = prices[0] + prices[number_of_prices - 1];
   }
   else if (number_of_prices == 1)
   {
       // Only one element in the array
       sum = prices[0];
   }

   cout << fixed << setprecision(2);
   cout << "Sum of first and last: " <<  sum << endl;

   return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: