I need help with C#

I’m stuck on my third assignment for my Intro to C# course. Here’s what I need to program:

Write a C# Console application that depending on user’s choice prints either a diamond shape or a triangle shape.

If the user enters the number 1, this program will print the first shape (diamond shape), if the user enters the number 2 the program will print the second shape (triangle shape).

Use the Write and WriteLine methods, to print a single asterisk (*) or space “ “. Use the for structure to implement nested loops and minimize the number of output statements.

Use a switch structure to help determine what shape will be printed, and use Read or ReadLine methods to obtain the user’s choice number.

Here’s all the codings that I have so far:

using System;

public class ShapeSwitch
public static void Main()
//prompt the user to enter either 1 or 2 to output the specified shape
Console.WriteLine("Enter 1 to output the diamond shape
" +
"Enter 2 to output the triangle shape
Console.Write("Please enter your selection: ");
string input = Console.ReadLine();
int choice = int.Parse(input);

		case 1: 
		case 2:   
			Console.WriteLine("Invalid selection. Please select 1 or 2.");            
	Console.WriteLine("Thank you!");


So my question is, how do I use the ‘for’ structure to output the asterisks so that it either forms a ‘diamond’ shape or a ‘triangle’ shape?

You’ll need more than one for statement. Divide the shape printing into repetitive subtasks. For example, one for loop can print one line with each iteration. Inner loops can print individual symbols.

And… How do I do that…? -_-
Sorry, I’m so clueless.

[EDIT] Something like this maybe?

int inner;
for (int outer = 0; outer < 3; outer ++)
for(inner = 10; inner > 5; inner–)
Console.WriteLine(“Outer: {0} Inner: {1}”, outer, inner):

I copied that straight out of my textbook. I think you’re trying to tell me to do something like that to output the shapes, right?

Yes. Try drawing out the shapes first, then devise a way to print out that pattern, one line at a time. For example to print a diagonal line:

for (int j=0; j&lt5; ++j){
for (int k=0; k&ltj; ++k){
Console.Write(" “);

note: I don’t actually use C# so this program might not compile the way it is.
basically it goes like this: for each line, print a number of spaces equal to the number of that line, then print a *. The result will be


It depends on how strictly your instructor is definiting “triangle” and “diamond”.

Oh wait, Vorpy’s on the job, so you’re in good hands. skedaddles

Like this:

Thanks, Vorpy! I still need to figure out how to do the ‘triangle’ shape though… Cause right now, all I could do is this:



[EDIT] Never mind~ got it! Now all that’s left is the diamond shape…