Need help in code in TURBO C... ASAP

Page 1 of 1

4 Replies - 2519 Views - Last Post: 26 August 2007 - 07:57 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=32223&amp;s=5b278a26f0d24c80141502f21966c5a6&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 cliverevric

Reputation: 0
• Posts: 28
• Joined: 25-August 07

Need help in code in TURBO C... ASAP

Posted 25 August 2007 - 10:32 AM

I would like to ask for help in my homework in TURBO C...
Our first item was a cross which size depends on user input...
The conditions are: input is odd number, ranging from 3-99, after a run, ask for input (1/0) in order to continue/end, respectively..
I used this code:
```#include<stdio.h>
int b;
main()
{
int x, y, a;
clrscr();
b=1;
while(b !=0)
{
clrscr();
scanf("%d", &a);
if(a%2==1)
{
if(3<=a||a>100)
{
for(x=1;x<=a;x++)
{
for(y=1;y<=a;y++)
{
if(y==((a/2)+1))
{ printf("*"); }
else if(x==((a/2)+1))
{ printf("*"); }
else
{ printf(" "); }
}
printf("\n");
}
}
else
{ printf("INVALID!"); }
}
else
{ printf("INVALID!"); }

printf("[1] to continue [0] to end...");
scanf("%d", &b);
}
clrscr();
printf("Thanx!");
getch();
}

```

My problem is the second item, same conditions, but the figure is a ribbon... I can't figure out what to replace the IF/ELSE statements...
I tried changing the IF statement to
```IF(y==1||y==a) { printf("*"); }
```

and the out put is a figure of "H"... am I close to getting the ribbon figure?
Please give me hints on what to do.... THANX!!!

example of the ribbon:
INPUT=5
*___*
**_**
*****
**_**
*___*

"_" is equivalent to space

INPUT=7
*_____*
**___**
***_***
*******
***_***
**___**
*_____*

Is This A Good Question/Topic? 0

Replies To: Need help in code in TURBO C... ASAP

#2 PennyBoki

• D.I.C Lover

Reputation: 55
• Posts: 2,345
• Joined: 11-December 06

Re: Need help in code in TURBO C... ASAP

Posted 25 August 2007 - 02:36 PM

Since you got the form of H, you are very near, but for your case I would use a 2d char array, fill the 2d array with on symbol first e.g. with '*', and then just change the array using another for loop and just replace the '*' with '_' where needed.

#3 cliverevric

Reputation: 0
• Posts: 28
• Joined: 25-August 07

Re: Need help in code in TURBO C... ASAP

Posted 26 August 2007 - 06:40 AM

Hmmm.. I'm afraid I'm not familiar with the term 'char 2d array.' Would you kindly elaborate? Or give an example maybe? I'm sorry, I'm just a newbie when it comes to turbo C.

By the way, the underscore in the figures juz represent the blank areas.

Also, you said that I should use a FOR LOOP.. should I replace the IF-ELSE with it?

Any more hints? Coz I really need to solve it ASAP... I'm sorry for the iconvenience... And thank you for the reply. Have a nice day.

#4 PennyBoki

• D.I.C Lover

Reputation: 55
• Posts: 2,345
• Joined: 11-December 06

Re: Need help in code in TURBO C... ASAP

Posted 26 August 2007 - 07:00 AM

Here is a sample code(very poor though) to demonstrate a 2d char array, that is my idea to fill the array with '*' and the do the for loop.
Now the for loop you'll need should be manipulated according the values of the input. Good luck on this.

NOTE: this code is not a solution of your problem, it's far from it, but it could give you the idea to help you manipulate in order to reach your solution.
```#include <stdio.h>
#define MAX 99
int main()
{
char a[MAX][MAX];
char x=' ';
char y='*';
int i, j;

for(i=0;i<7;i++)
{
printf("\n");
for(j=0;j<7;j++)
{
a[i][j]=y;
printf("%c", a[i][j]);
}
}
printf("\nHit ENTER to exit\n");
fflush(stdout);
(void)getchar();
return 0;
}
```

#5 cliverevric

Reputation: 0
• Posts: 28
• Joined: 25-August 07

Re: Need help in code in TURBO C... ASAP

Posted 26 August 2007 - 07:57 AM

I see now.. about the code, there's an error on the variable x, so i deleted "char x=' ';" then it ran. So, all I have to do now is to figure out the LOOP st8ment for my RIBBON. I'd be happy if you'd send it to me, but I know you guys here don't toler8 that kind of stuff.. (Still, I wish you'd do..) NYAHAHA!!! DARN RIBBON!!!

Thanx for your time and Have a nyc day!!!