• Skip to main content
  • Skip to footer

SoftwareProg.com

Software programming learning aide

  • Blog
    • Discussion
  • News
  • CS50’s Introduction to Computer Science by Harvard University on Edx
    • Week 1
    • Week 2
    • Week 3
    • Week 4
    • Week 5

What is wrong with this do while loop

CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1 › What is wrong with this do while loop

Tagged: do while loop in c

  • This topic is empty.
Log In Register Lost Password
Viewing 1 post (of 1 total)
  • Author
    Posts
  • August 27, 2022 at 5:40 am #480
    admin
    Keymaster

      d is included as integer type. So why in line 70, d is marked as not defined.


      Copy Code
      Copied
      Use a different Browser

      
      
      #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)
      
      {
        do
         {
          int 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;
      }


      Reply


      https://edstem.org/us/courses/176/discussion/1701132?[learn_press_profile]

    • Author
      Posts
    Log In Register Lost Password
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Log in / Register

    Initiative by Digital Splendid OPC Pvt. Ltd.