Diamond shape

problem with formatting

Page 1 of 1

3 Replies - 18002 Views - Last Post: 15 December 2007 - 03:37 AM Rate Topic: -----

#1 salman  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 21-November 07

Diamond shape

Post icon  Posted 14 December 2007 - 09:00 AM


#include <stdio.h>
#include <conio.h>
void main ()
{
clrscr ();
int a, b, star;   //integor declaration

//starting point of upper diamond shape loop
for (a = 1; a <=7; a+=2)
{
gotoxy (36, a+12);
for (b = (10 - a) /2; b >0; b--)
{
printf (" ");
}
for (star = 1;  star <= a;  star++)
{
 printf ("*");
}
printf ("\n");
}
//ending point of upper diamond shape loop



//staring point of bottom diamond shape loop
for (a = 5;  a >= 0;  a -= 2)
{
gotoxy (b, a-12);
for (b = (10 - a) /2; b > 0; b--)
{
printf (" ");
}
for (star = 1;  star <= a;  star++)
{
printf("*");
 }
printf ("\n");
}
getch ();
}
//ending point of bottom diamond shape loop





The upper part of the diamond is giving me accurate result, it display in center from top to bottom and also left to right.
But the bottom part of the diamond shape is not giving me accurate result.
I think there is a problem of gotoxy statement in the bottom diamond shape program.
So guide me to point out this problem.

Thanx.

Is This A Good Question/Topic? 0
  • +

Replies To: Diamond shape

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Diamond shape

Posted 14 December 2007 - 09:27 AM

Please describe the problem in detail. What is the actual output, and what is the expected output?
Was This Post Helpful? 0
  • +
  • -

#3 salman  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 21-November 07

Re: Diamond shape

Posted 15 December 2007 - 03:16 AM

View PostAmadeus, on 14 Dec, 2007 - 09:27 PM, said:

Please describe the problem in detail. What is the actual output, and what is the expected output?

The actual output is attach with this message. so download it and see and solve this problem.
in this attachment u will see the half diamond shape is in ceter of the screen but the rest part of the diamond is not in the center it is in left side of screen so help me to make the complete diamond shape to the center of the screen.

I hope you will understand what i want to do.

so help me as far as possible.

Thanks!.

Attached File(s)


This post has been edited by salman: 15 December 2007 - 03:29 AM

Was This Post Helpful? 0
  • +
  • -

#4 jjhaag  Icon User is offline

  • me editor am smartastic
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: Diamond shape

Posted 15 December 2007 - 03:37 AM

If you think that the problem is with the gotoxy() statement, toss them out of the program and see what happens. I did so and it prints out a nice diamond. But just so you know, the reason that I tossed the gotoxys, as well as the clrscr() call, is that these are not part of standard C, and they are not available on my system.

However, I can see one potential problem. In the first call to gotoxy, you position the cursor at (36, a+12), while in the second, you position it at (b, a-12). I have a feeling that the problem lies with the "b" in the second call (it would seem that you should be using 36 again as the x coordinate), but since this isn't available to me, I can't test that. Try it out and see what happens.

This post has been edited by jjhaag: 15 December 2007 - 03:38 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1