I need some help with my assignment. I need to create an array amounts to store five elements and then two arrays of five elements with the names dollars and cents. My problem is that I cant understand how to store the whole number part of each value in the amounts array in the corresponding element of dollars and the fractional part of the amount as a two-digit integer in cents(like if I input 2.75 - store 2 in dollars array and 75 in cents array).Any suggestions on how to do this would be appreciated! Thanks
This is what I have for now:
void main()
{
float amounts[5];
long dollars[5];
long cents[5];
int i = 0;
printf("Enter five monetary values separated by spaces:\n");
for(i = 0; i<5 ; i++)
scanf("%f", &amounts[i]);
for (i = 0; i<5; i++){
printf ("\ni=[%d], dollars: %.2f, cents: %.2f\n", i, dollars, cents);
}
printf("\nYou entered the values: \n");
for(i = 0; i<5 ; i++)
printf("$%.2f\n", amounts[i]);
printf("\n");
}
amounts[i]todollarsand `cents'. How would you determine the whole number of a floating point number? When you have the whole number, how can you determine the fractional portion? Hope this helps.