Feedback for these lessons is very much welcome. If you like or hate something about a lesson let us know, either on GitHub, via Mail or just tell us in person ;)
x
Customized Sheldon
Write a program, that lets the user decide how often “Knock, knock, knock - Penny?” is printed.
Experts: Let the program additionally ask how often Sheldon knocks each time. Take care, that the first “Knock” starts with a Capital K.
###Hints###
Experts: You can use loops inside loops
Experts: You should use a different index for the inner loop
##Solution##
#include <stdio.h>
int main(void) {
int count;
int knock;
printf("How often shall sheldon try to knock? ");
scanf("%d", &count);
printf("And how often shall he knock each time? ");
scanf("%d", &knock);
while (count-- > 0) {
int i;
for (i = 0; i < knock; ++i)
if (i == 0)
printf("Knock");
else
printf(", knock");
if (knock > 0)
printf(" - ");
printf("Penny?\n");
}
return 0;
}