I made a code to draw a christmas tree in the c console, however, the last for loop for making a tree trunk under it doesn't work.. can somebody help? code:
#include <math.h>
#include <stdio.h>
#include <stdint.h>
int breedte, invoer, boom, spatie, indent, voet, links, rechts, stam;
int i;
int main(void) { //verander dit naar Main om het programma te runnen in visual studio
printf("voer een getal in \n");
scanf_s("%d", &invoer);
breedte = 1;
boom = 1;
spatie = invoer / 2;
indent = 1;
voet = invoer / 2;
links = voet - (0.25 * invoer);
rechts = voet + (0.25 * invoer);
stam = links;
i = 10;
do{
indent = spatie;
while (indent > 0) {
printf(" ");
indent = indent - 1;
}
while (breedte > 0) {
printf("+");
breedte = breedte -1;
}
printf("\n");
boom = boom + 2;
breedte = boom;
spatie = spatie - 1;
} while (boom <= invoer && boom <= 80);
for (int x = 0; x <= i; x++) {
while (links >= 0) {
printf(" ");
links = links - 1;
}
while (stam < rechts) {
printf("+");
stam = stam + 1;
}
printf("\n");
}
}
the important part is:
for (int x = 0; x <= i; x++) {
while (links >= 0) {
printf(" ");
links = links - 1;
}
while (stam < rechts) {
printf("+");
stam = stam + 1;
}
printf("\n");
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. An vero, inquit, quisquam potest probare, quod perceptfum, quod. Efficiens dici potest. Duo Reges: constructio interrete. Hoc dictum in una re latissime patet, ut in omnibus factis re, non teste moveamur. Ut aliquid scire se gaudeant? Eadem nunc mea adversum te oratio est.
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>
int breedte, invoer, boom, spatie, indent, voet, links, rechts, stam;
int i,x,y;
int main(void) { //verander dit naar Main om het programma te runnen in visual studio
printf("voer een getal in \n");
scanf("%d", &invoer);
breedte = 1;
boom = 1;
spatie = invoer / 2;
indent = 1;
voet = invoer / 2;
links = voet - (0.25 * invoer);
rechts = voet + (0.25 * invoer);
stam = links;
i = 10;
do{
indent = spatie;
while (indent > 0) {
printf(" ");
indent = indent - 1;
}
while (breedte > 0) {
printf("+");
breedte = breedte -1;
}
printf("\n");
boom = boom + 2;
breedte = boom;
spatie = spatie - 1;
} while (boom <= invoer && boom <= 80);
x = links;
y = stam;
for (int xt = 0; xt <= i; xt++) {
for(int p = 0; p<x; p++) {
printf(" ");
}
x--;
for(int q=0;q<y && y<rechts; q++){
printf("+");
}
y=y+2;
printf("\n");
}
}
fixed the code for the trunk. you can check the logic for the spacing in the trunk.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.