1.11M Members

C# programming

 
0
 

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

 
0
 

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

 
0
 

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

 
0
 

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

 
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

 
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

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

 
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.

 
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

 
2
 

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.

 
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("/");}	
				
				}
 
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!!

 
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.

 
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.

 
0
 
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();
            }
 
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.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: