IT, Programming, & Web Development › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1: [C] – Data Types, Operators, Conditional Statements, Loops, and Command Line › What is wrong with this do while loop
Tagged: do while loop in c
- This topic is empty.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
August 27, 2022 at 5:40 am #480
d is included as integer type. So why in line 70, d is marked as not defined.
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#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; }
[/dm_code_snippet]
Reply
https://edstem.org/us/courses/176/discussion/1701132?[learn_press_profile]
-
AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.