| Thread Closed |
C++ troubles |
Share Thread | Thread Tools |
| Nov14-06, 11:19 PM | #1 |
|
|
C++ troubles
Hey,
Im pretty new to c++ so my knowledge is limited. I have been set an assignment to create the following triangles only using Do...While loops. I'm having difficulty trying to code it. The underscores are just their to illustrate spaces. 1 *_________________5 * 5__________* * * * 1 * ____3 * __2 * *_____________* 4 *___________* * * 2 *______2 * * ____3 * * *______3 * 3 * 3 * 3________* * 3 * ______1 * * * __4 * * * *______* 2 * 2 * 2 * ________* 4 * _____4 * * * * 5 * * * * *___1 * 1 * 1 * 1 * 1 * 1______5 *____5 * * * * * I have split the shapes into two, with the top half being 3 lines and the bottom half the remaining 2. However, as fas as i can tell this only works for the first shape. #include <stdio.h> void main() { // Declaring the variables int row,space,number,x, number1, number2; // Inserting numbers into variables row=1; number=1; number1=1; number2=1; do // Top of shapes { space=1; // First Triangle do { printf(" "); space++; } while (space<=row); printf("%d", number); number++; x=1; do { printf("* "); x++; } while (x<=row); space=3; do { printf(" "); space--; } while (space>=row); space=5; // Second Triangle do { printf(" "); space--; } while (space>=row); x=1; do { printf("%d * ", number1); x++; } while (x<=row); printf("%d", number1); number1++; space=5; do { printf(" "); space--; } while (space>=row); printf("\t"); space=1; // Third Triangle do { printf(" "); space++; } while (space<=row); x=5; do { printf("* "); x--; } while (x>=row+1); printf("%d *", number2); number2++; printf("\n"); row++; } while (row<=3); do // Bottom Of shape { space=5; // First Shape do { printf(" "); space--; } while(space>=row); printf("%d", number); number++; x=1; do { printf("* "); x++; } while (x<=row); space=1; do { printf(" "); space++; } while (space<=1); space=5; // Second Triangle do { printf(" "); space--; } while (space>=row); x=1; do { printf("%d * ", number1); x++; } while (x<=row); printf("%d", number1); number1++; space=5; do { printf(" "); space--; } while (space>=row); printf("\t"); space=1; // Third Triangle do { printf(" "); space++; } while (space<=row); printf("* "); printf("%d *", number2); number2++; printf("\n"); row++; } while (row<=5); } |
| Nov21-06, 06:23 PM | #2 |
|
|
It would help if you showed what output that gave you. It is kind of hard working with uncommented, unspaced code. Try using the command? I think they have that here.
|
| Dec15-06, 12:19 PM | #3 |
|
|
why to write such a big progarm.let me say you in a simple method using for loops.
#include<stdio.h> #include<conio.h> main() { int i,n,j; clrscr(); printf("enter the elements"); for(i=0;i<=n;i++) { for(j=0;j<=n;j++) { printf("%d",j); } printf("\n"); } getch(); } if you will declare i in place of ("%d",i) you will get the reverse triangle |
| Thread Closed |
| Thread Tools | |
Similar Threads for: C++ troubles
|
||||
| Thread | Forum | Replies | ||
| Dynamics troubles | Introductory Physics Homework | 3 | ||
| Wireless troubles | Computing & Technology | 14 | ||
| Laptop Troubles | Computing & Technology | 6 | ||
| Calculus troubles.. yay. | Calculus & Beyond Homework | 1 | ||
| more differentiation troubles | Introductory Physics Homework | 2 | ||