0

I initially wrote this with float instead. It was meant to use %.2f instead of integers I assume my syntax was wrong.

Following code works perfectly I just need to know how to turn it into float.

#include <stdio.h>
#include <stdlib.h>
main()
{
  int bills[] = {1000, 500, 200, 100, 50, 20, 10, 5, 1, 0.5, 0.25};
  int values[10];
  int y[10];
  int yt;
  for(int i = 0; i <= 10; i++) {
      printf("%d  \t", bills[i]);
      scanf("%d", &values[i]);
      y[i] = bills[i] * values[i];
      printf("=  %d\n", y[i]);
      yt += y[i];
  }
  printf("%d", yt);
}
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 1
    Do not turn it into float. Int is better. https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency – Yunnosch Mar 12 '22 at 08:45
  • I doubt that it works with int and `0.5, 0.25`. But still, use int, just multiply by 100. – Yunnosch Mar 12 '22 at 08:46
  • I vote to close as not reproducable, because with an input of 0,0,0,0,0,0,0,0,0,1,1, i.e. 0.5+0.25 I get an output of 512. Which is definitly incorrect and implies wrong useage of 0.5 and 0.25 and a lack of initialising `yt`. I.e. this definitly does not "works perfectly". And cannot be converted meaningfully to float, even if I would try it, see above. – Yunnosch Mar 12 '22 at 08:51
  • I just would copy the int array into an float array because i dont know any function or way to change a data type of an array – zlSxrtig Mar 12 '22 at 11:24

0 Answers0