Need help in code in TURBO C... ASAP

help in printing ribbon in TURBO C

Page 1 of 1

4 Replies - 2040 Views - Last Post: 26 August 2007 - 07:57 AM Rate Topic: -----

#1 cliverevric  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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();
   printf("Please enter a number:");
   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
*_____*
**___**
***_***
*******
***_***
**___**
*_____*

:D :D :D

Is This A Good Question/Topic? 0
  • +

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

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 cliverevric  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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. :D

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? :D Coz I really need to solve it ASAP... I'm sorry for the iconvenience... And thank you for the reply. Have a nice day. :^:
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • 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;	
}

Was This Post Helpful? 0
  • +
  • -

#5 cliverevric  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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!!! :rolleyes: DARN RIBBON!!! :angry:

Thanx for your time and Have a nyc day!!! :^: :^: :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1