We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,676 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

C# programming

hey guys!

do you have idea how to print a * and in a square symbol

like this

*****
* *
* *
* *
*****

i have my code in here but it didnt follow like that

7
Contributors
14
Replies
3 Days
Discussion Span
3 Years Ago
Last Updated
15
Views
reyarita
Light Poster
26 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I don't get you. Can you be a little more specific?

farooqaaa
Posting Whiz in Training
295 posts since Jul 2008
Reputation Points: 61
Solved Threads: 71
Skill Endorsements: 0

What do you have so far (for the code)? Hint: You'll need to use "for."

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 583
Skill Endorsements: 11

Well can you please post your code, or could be more specific about your problem..........:)

avirag
Posting Whiz
313 posts since Jun 2009
Reputation Points: 31
Solved Threads: 36
Skill Endorsements: 0

I think I know what you want to do, you want to print the char '*' but make them it print in a form of a square?

Like so:

*****
*\\\\\*
*\\\\\*
*****

Where the '\'s are blank space (multi spaces are not supported here I presume)

For that you would have to use a for loop

What I would do is the following:
I would have a string showing what I would want to print, and have key charectars showing where to end the line and where to show background etc.

const string box = "****************$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "****************$"+
			
			for(int i=0; i < box.Length; i++)
				{
					if(avatar[i]!='/'){
					Console.ForegroundColor = ConsoleColor.Blue;
						if(box[i]=='$'){Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("/");}
						else{Console.Write(box[i]);}
					}
				else{Console.ForegroundColor = ConsoleColor.Green;Console.Write("/");}	
				
				}

Try that

NargalaX
Junior Poster in Training
69 posts since Aug 2009
Reputation Points: 18
Solved Threads: 1
Skill Endorsements: 0

I think I know what you want to do, you want to print the char '*' but make them it print in a form of a square?

Like so:

*****
*\\\\\*
*\\\\\*
*****

Where the '\'s are blank space (multi spaces are not supported here I presume)

For that you would have to use a for loop

What I would do is the following:
I would have a string showing what I would want to print, and have key charectars showing where to end the line and where to show background etc.

const string box = "****************$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "****************$"+
			
			for(int i=0; i < box.Length; i++)
				{
					if(avatar[i]!='/'){
					Console.ForegroundColor = ConsoleColor.Blue;
						if(box[i]=='$'){Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("/");}
						else{Console.Write(box[i]);}
					}
				else{Console.ForegroundColor = ConsoleColor.Green;Console.Write("/");}	
				
				}

Try that

yap

ure ryt. like a square

*****
*\\\\\*
*\\\\\*
*\\\\\*
*****

"\" just symbol it has a blankspace
but mine is like dis

*****
*****
*****
*****
*****

reyarita
Light Poster
26 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I did this at University last year. Had to feed in dimensions and have it print a square of that size. Had to do it with triangles and hexegons aswell.

You need a for loop.

JayOne
Newbie Poster
13 posts since Dec 2009
Reputation Points: 17
Solved Threads: 0
Skill Endorsements: 0

I did this at University last year. Had to feed in dimensions and have it print a square of that size. Had to do it with triangles and hexegons aswell.

You need a for loop.

halo sir

i tried ure code
but i have a problem
it says: Error 1 The name 'avatar' does not exist in the current context

sir Im really sorry. Im a beginner in c#, my teacher just give me us an exercise when we first met. den i really didnt understand a little about programming coz our teacher here is, just give us the code and we will self study that code, but i really cant understand whats that code for. Our teacher here didnt explain very well every codes. They think that were genius but were not. thats why i keep myself bc study and searching about whats that code for but it doesnt really helps me a lot but a little bi. I really want to have a teacher who can explain very well in every code. Most of the student here has no knowledge\learning in programming. thats why i really disappointed how da teacher teachs. I really want to become a programmer but now I doubt it.

thanks for your reply sir!!

HAppy new year

reyarita
Light Poster
26 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Universities are usually like that.

If you don't understand, grab a book from your library, or ask one of the teachers for help. Last thing you want is to fail and exam because you don't understand.

You should really understand the fundementals such as for loops. Thats really as basic as it gets. Do yourself a favour ... because I've been in your shoes. Go grab a book and spend a day with it before you attempt to code a solution to the problem :) My bit of advice.

JayOne
Newbie Poster
13 posts since Dec 2009
Reputation Points: 17
Solved Threads: 0
Skill Endorsements: 0

Oops! Im sorry, I wrote one variable wrong in the code.

Here is a fixed version :

const string box = "****************$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "*//////////////*$"+
				 "****************$"+
			
			for(int i=0; i < box.Length; i++)
				{
					if(box[i]!='/'){
					Console.ForegroundColor = ConsoleColor.Blue;
						if(box[i]=='$'){Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("/");}
						else{Console.Write(box[i]);}
					}
				else{Console.ForegroundColor = ConsoleColor.Green;Console.Write("/");}	
				
				}
NargalaX
Junior Poster in Training
69 posts since Aug 2009
Reputation Points: 18
Solved Threads: 1
Skill Endorsements: 0

hey Thanks sir! for sharing your knowledge.
I promise that i will do my best to understand this.
and also with your help

thanks again sir!!

reyarita
Light Poster
26 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

halo sir!!
Happy New Year!!

I've tried ure code its run but one thing is

the starisk should look like this

5 starisk horizontal and vertical

looks like this

*****
*|||||*
*|||||*
*|||||*
*****
Note: this " | " symbol should not be included only a atarisk

Thaks sir
Hoping for your reply.

reyarita
Light Poster
26 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You need a for loop over all of the rows, a for loop for each row (with an if statement to switch from printing spaces to printing stars (so at column a and column b I need a star, the rest I need spaces)). It sounded like you had a lot of it, just put some " " spaces in where appropriate.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 583
Skill Endorsements: 11
for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (i == 0 || j == 0 || i == 7 || j == 7)
                    {
                        Console.Write("*");
                    }
                    else { Console.Write(" "); }
                }
                Console.WriteLine();
            }
shank123
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

shank123,
Thanks for helping the poster. However, in the spirit of truly helping posters with their homework, it's best not to give the answer away completely.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 583
Skill Endorsements: 11

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1100 seconds using 2.76MB