Computer Science, asked by harsh20095, 3 months ago

Write a program to accept any number and calculate its Integer value

Answers

Answered by as8859377960
0

Answer:

/*This program acts as a coin changer that helps to provide

 change user their changes in the highest amount.

*/

#include <stdio.h>

// Delcaration of functions

int coins(int fifty, int twenty, int ten, int five);

int main()

{

   // Declare and initialize working storage

   int fifty = 0;

   int twenty = 0;

   int ten = 0;

   int five = 0;

   int user_input = 0;

   int counter = 3;

   int coins(int fifty, int twenty, int ten, int five);

   // Prompt user for input, prints, and loops for 3 attempts

   while (counter > 0)

   {

       printf("\nPlease enter an amount within the range of 5 to 95\n");

       printf("\nPlease enter the amount you wish to change: \n\n");

       scanf("%d", &user_input);

       if ((user_input < 5) || (user_input > 95))

       {

           printf("\nInvalid input\n");

           printf("\nNumber of attemps: %d\n\n\n\n", counter);

       }

       counter--;

   }

   printf("\nYou have exceeded the number of attempts\n");

   // Compute number of coins to be given

   fifty = user_input / 50;

   twenty = user_input / 20;

   ten = user_input / 10;

   five = user_input / 5;

   if (fifty >= 1)

   {

       printf("\nNumber of fifty cent coins are: %d\n", fifty);

   }

   else if (twenty >= 1)

   {

       printf("\nNumber of twenty cent coins are: %d\n", twenty);

   }

   else if (ten >= 1)

   {

       printf("\number of ten cent coins are: %d\n", ten);

   }

   else if (five >= 1)

   {

       printf("\nNumber of five cent coins are: %d\n", five);

   }

   return 0;

}

Explanation:

Similar questions