C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old February 24th, 2004, 09:00 PM
alzarius alzarius is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 alzarius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can anyone help me with this C++ problem?

#include<iostream>

using namespace std;

void main()
{

int userInput;
char userChar;
char mySpace = ' ';

cout << "Enter a number:" << endl;
cin >> userInput;
cout << "Enter any character:" << endl;
cin >> userChar;

if (userInput % 2 == 0)
{
userInput++;
}

for(int i=1; i <= userInput; i=i+2)
{
for(int j=1; j <= (userInput-i)/2; j++)
{
cout << mySpace;
}
for(int k=1; k <= i; k++)
{
cout << userChar;
}



cout << endl;
}
}


This prints a diamond, well, half of it. I can get the top part to work fine but cant get the bottom to "close"

____*____
___***___
__*****__

thats as far as it gets. I dont know how to write the loop to decrement it to make it close. Can anyone help?

Reply With Quote
  #2  
Old February 25th, 2004, 06:25 AM
Izkata Izkata is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 6 Izkata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hehe, kool.... I've not seen anything like this before, so if I get a chance later, I'll take a look at it, k?

Reply With Quote
  #3  
Old February 26th, 2004, 06:16 AM
Izkata Izkata is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 6 Izkata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Alright, I *think* I got what our looking for... Add this loop just after the first for loop:

for(int i=userInput; i >= 0; i=i-2)
{
for(int j=1; j <= (userInput-i)/2; j++)
{
cout << mySpace;
}
for(int k=1; k <= i; k++)
{
cout << userChar;
}
cout << endl;
}

Reply With Quote
  #4  
Old March 8th, 2004, 04:26 AM
Ikyikypdtong Ikyikypdtong is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 Ikyikypdtong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This should work:
Code:
#include<iostream.h>

	int userInput;
	char userChar;
	char mySpace = ' ';

void input()
{
	cout << "Enter a number:" << endl;
	cin >> userInput;
	cout << "Enter any character:" << endl;
	cin >> userChar;

	if (userInput % 2 == 0)
	{
		userInput++;
	}
}

void print1()
{
		for(int i=1; i <= userInput; i=i+2) 
		{
			for(int j=1; j <= (userInput-i)/2; j++)
			{
				cout << mySpace;
			}
			for(int k=1; k <= i; k++)
			{
				cout << userChar;
			}
			cout << endl;
		}       
}


void print2()
{
		for(int i=userInput; i >= 0; i=i-2)
		{
			for(int j=1; j <= (userInput-i)/2; j++)
			{
				cout << mySpace;
			}
			for(int k=1; k <= i; k++)
			{
				cout << userChar;
			}

			cout << endl;
		}
}

int main()

{                                          
	input();

	print1();

         print2();

	
	return 0;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Can anyone help me with this C++ problem?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway