GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Apr-2006, 07:02
Zayne Zayne is offline
New Member
 
Join Date: Apr 2006
Posts: 7
Zayne is on a distinguished road
Lightbulb

Diamond Shape of Star (*) Symbols


Hey... Sorry about my previous undescriptive post!

I am new to C++! And i've recently been given the following question to complete:

Write a program to design the output in a diamond shape of star symbols


I have tried to write the program using the following code:

CPP / C++ / C Code:
#include <iostream>
using namespace std;
void print (int rowsize);
int main()
{
	int rowsize;
	do{
		cout<<"Please type in a positive odd integer: ";
		cin>>rowsize;
	}while((rowsize%2==0)||(rowsize<=0));
	print(rowsize);
	return (0);
}
void print(int rowsize)
{
	int spaces=rowsize/2, currentsize=1, counter, count;
	for(counter=0;counter!=(rowsize+1)/2;counter++){
		for(count=spaces;count!=0;count--)
			cout<<" ";
		spaces--;
		for(count=currentsize;count!=0;count--)
			cout<<"*";
		currentsize+=2;
		cout<<endl;
}
currentsize=rowsize-1;
spaces+=2;
for(counter=rowsize/2;counter!=0;counter--){
	for(count=0;count!=spaces;count++)
		cout<<" ";
	spaces++;
	for(count=currentsize;count!=0;count--)
		cout<<"*";
	currentsize-=2;
	cout<<endl;
	}
}

However it doesn't seem to allow me to use EVEN numbers, and the bottom star does not show.

Any help will be greatly appreciated...
Last edited by LuciWiz : 21-Apr-2006 at 07:22. Reason: Added code tags
  #2  
Old 21-Apr-2006, 07:07
Zayne Zayne is offline
New Member
 
Join Date: Apr 2006
Posts: 7
Zayne is on a distinguished road

Re: Diamond Shape of Star (*) Symbols


Sorry I forgotten to use the code tags!

CPP / C++ / C Code:
#include <iostream>
using namespace std;
void print (int rowsize);
int main()
{
int rowsize;
do{
cout<<"Please type in a positive odd integer: ";
cin>>rowsize;
}while((rowsize%2==0)||(rowsize<=0));
print(rowsize);
return (0);
}
void print(int rowsize)
{
int spaces=rowsize/2, currentsize=1, counter, count;
for(counter=0;counter!=(rowsize+1)/2;counter++){
for(count=spaces;count!=0;count--)
cout<<" ";
spaces--;
for(count=currentsize;count!=0;count--)
cout<<"*";
currentsize+=2;
cout<<endl;
}
currentsize=rowsize-1;
spaces+=2;
for(counter=rowsize/2;counter!=0;counter--){
for(count=0;count!=spaces;count++)
cout<<" ";
spaces++;
for(count=currentsize;count!=0;count--)
cout<<"*";
currentsize-=2;
cout<<endl;
}
}
  #3  
Old 21-Apr-2006, 15:29
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,435
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Diamond Shape of Star (*) Symbols


Look at the loop for printing the second set of stars. You are outputting an extra one as you decrement.
__________________

Definition: Politics
Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error C2106: '=' : left operand must be l-value monalin C++ Forum 17 01-Sep-2007 10:03
How to display a diamond made with (2*n-1) lines? Pogomojo C++ Forum 2 06-Apr-2006 20:08
Help with Shape Program with stars qwestone C++ Forum 4 29-Apr-2005 07:57

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:18.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.