• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #486
    admin
    Keymaster
      
      
      #include <stdio.h>
      #include <cs50.h>
      
      int entercents(void);
      int count25(int b);
      int remainingafter25(int b);
      int count10(int b);
      int remainingafter10(int b);
      int count5(int b);
      int remainingafter5(int b);
      int count1(int b);
      
      int main(void)
      {
          int b = entercents();
          printf("result is %i\n", b);
      
          int c25 = count25(b);
          printf("count25 is%i", c25);
      
          int r25 = remainingafter25(b);
          printf("remaining after 25count is %i", r25);
      
          b = r25;
      
          int c10 = count10(b);
          printf("count10 is %i", c10);
      
          int r10 = remainingafter10(b);
          printf("remaining after 10count is %i", r10);
      
          b = r10;
          int c5 = count5(b);
          printf("count5 is %i", c5);
      
          int r5 = remainingafter5(b);
          printf("remaining after 5count is %i", r5);
      
          b = r5;
          int c1 = count1(b);
          printf("count1 is %i", c1);
      
          int totalcoins = c25 + c10 + c5 + c1;
          printf("totalcoins %i", totalcoins);
      
      }
      
      int entercents(void)
      
      {
          int d;
          do
          {
              d = get_int("enter cents");
          }
      
          while (d < 0);
          return d;
      }
      
      int count25(int b)
      {
          int x = b / 25;
          return x;
      }
      
      int remainingafter25(int b)
      {
          int x = b % 25;
          return x;
      }
      
      int count10(int b)
      {
          int x = b / 10;
          return x;
      }
      
      int remainingafter10(int b)
      {
          int x = b % 10;
          return x;
      }
      
      int count5(int b)
      {
          int x = b / 5;
          return x;
      }
      
      int remainingafter5(int b)
      {
          int x = b % 5;
          return x;
      }
      
      int count1(int b)
      {
          int x = b / 1;
          return x;
      }

      Cash project will help learn creating functions in C. Once you execute the function for 25 cents successfully, replicate the same for 10, 5, and 1 cents. For 1 cents, there is no need to apply division and modulus operator (though I have applied this to maintain uniformity) as say remaining cents after 5 cents is 4 cents. So 4 cents will be the count of the number of coins.

      cash project[learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top