Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,173 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,940 people online right now. Registration is fast and FREE... Join Now!




Diamond shape

 
Reply to this topicStart new topic

Diamond shape, problem with formatting

salman
14 Dec, 2007 - 08:00 AM
Post #1

New D.I.C Head
*

Joined: 21 Nov, 2007
Posts: 19


My Contributions
CODE


#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.

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Diamond Shape
14 Dec, 2007 - 08:27 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Please describe the problem in detail. What is the actual output, and what is the expected output?
User is offlineProfile CardPM
+Quote Post

salman
RE: Diamond Shape
15 Dec, 2007 - 02:16 AM
Post #3

New D.I.C Head
*

Joined: 21 Nov, 2007
Posts: 19


My Contributions
QUOTE(Amadeus @ 14 Dec, 2007 - 09:27 PM) *

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!.

This post has been edited by salman: 15 Dec, 2007 - 02:29 AM


Attached File(s)
Attached File  diamond.bmp ( 926.4k ) Number of downloads: 83
User is offlineProfile CardPM
+Quote Post

jjhaag
RE: Diamond Shape
15 Dec, 2007 - 02:37 AM
Post #4

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
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 Dec, 2007 - 02:38 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:43AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month