...

View Full Version : c programming (triangles)



glaze
02-04-2012, 12:13 PM
[CODE]
#include<stdio.h>

void Instruction(){
printf(" SHALOM!\n\n");
printf("Did you know that there are different types and sizes of a triangle?\n\n");
printf("If you don't I can take you there!!!!\n\n");
printf("so seatback and relax...and let your finger work...\n\n");
printf("You must first select the TYPE AND SIZE of triangle you want to execute (separated by space).\n\n");
printf("[A] REGULAR\n\n");
printf("*\n");
printf("**\n");
printf("****\n");
printf("[B] INVERTED\n\n");
printf("***\n");
printf("**\n");
printf("*\n");
printf("[C] FACING OPPOSITE DIRECTION OF THE REGULAR\n\n");
printf(" ***\n");
printf(" **\n");
printf(" *\n");
printf("[D] INVERTED FACING OPPOSITE DIRECTION\n\n");
printf(" *\n");
printf(" **\n");
printf(" ***\n");
printf("[E] PRINT ALL 4 TRIANGLES (one below the other).");
printf("SURPRISE! \n\n YOU HAVE THE MOST AMAZING TRIANGLE EVER!!!\n\n");
printf("If you WANT to try again enter 1 otherwise enter 0\n\n\n");
}
int main() {
Instruction();
int x, y, size, g=0, k;
int reg, inv,inv_face,opp;
char choice;
do {
printf("\n\n Enter your CHOICE and SIZE of the triangle(separated by a space):");
scanf("%c %d", &choice,&size);
printf("\n");
switch (choice){
case 'A':
reg = REGULAR(size);
break;
case 'B':
inv = INVERTED(size);
break;
case 'C':
opp = OPPOSITE(size);
break;
case 'D':
inv_face = INVERTED_FACING(size);
break;
case 'E':
reg = REGULAR(size);
inv = INVERTED(size);
opp = OPPOSITE(size);
inv_face = INVERTED_FACING(size);
break;
}
printf("\n Do you want to try again? [1-yes/0-no]:");
scanf("%d",&k);
printf("\n");
}while (k>0);
return 0;
}

int REGULAR(size){
int x,y, reg;
for (x=0; x<=size; x++) {
for (y=0; y<x; y++)
printf("*");
printf("\n");
}
return reg;
}

int INVERTED(size){
int x,y, inv;
for (x=0; x<=size; x++) {
for (y=size; y>x; y--)
printf("*");
printf("\n");
}
return inv;
}

int OPPOSITE(size){
int x,y,g=0,opp;
for (x=size; x>=1; x--) {
for(y=1; y<=g; y++)
printf(" ");
g++;
for (y=1; y<=x; y++)
printf("*");
printf("\n");
}
return opp;
}

int INVERTED_FACING(size){
int x,y,inv_face;
for (x=0; x<=size; x++) {
for(y=size; y>x; y--)
printf(" ");
for (y=1; y<=x; y++)
printf("*");
printf("\n");
}
return inv_face;
}

this is my program... and i don't have any idea where i commit my mistake.

please help me! :((((

glaze
02-04-2012, 12:14 PM
and i use code blocks 10.5 as my compiler.

abduraooft
02-04-2012, 12:44 PM
and i don't have any idea where i commit my mistake.
Do you get any errors?

glaze
02-04-2012, 12:56 PM
no i haven't but only when i try it again..

glaze
02-04-2012, 01:00 PM
Do you get any errors?

no i haven't but only when i press 1 and i try it again...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum