C - Write program to read numerical values with dollar sign, monetary amounts separated by commas and spaces

Requirements

Write a program that will read the numerical values

Example input:

$3.50  ,  $4.75 , $9.95 , $2.50

Calculate the total

Hint

use the following specification to ignore space, comma and dollar sign

"%*[ ,$]%lf"

Demo

#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#define COUNT 4/*from   ww  w.j  a v a 2s.  c om*/

int main(void)
{
  double amounts[COUNT] = { 0.0 };
  double total = 0.0;

  printf_s("Enter the %d amounts:\n", COUNT);
  for (size_t i = 0; i < COUNT; ++i)
  {
    scanf_s("%*[ ,$]%lf", &amounts[i]);
    total += amounts[i];
  }

  printf_s("The total of the input is: $%.2lf\n", total);
}

Result