Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Alright, how do i print a given number of a symbol per row, and then one less each row untill there is none left?

Question: Can i link "Console.Write("#"); - to the value of x or Y?

like this picture: http://csharpskolan.se/image.php?id=115[^]

My code is currently:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Oh Herro!");
            for (int y = 10; y >= 1; y--)
            {
                for (int x = 10; x >= 0; x--)
                {
                    Console.Write("#");
                }
             Console.WriteLine();
            }
        }
    }
}
Posted
Updated 4-May-11 5:07am
v4

I know it's homework, but we get so few opportunities to actually answer with code. Here's one way to do it:

C#
string pounds = "##########";

Console.WriteLine("Oh Herro!");
for(int i = 0; i < pounds.length; i++)
{
    Console.WriteLine(pounds.SubString(i));
}
Console.WriteLine();
 
Share this answer
 
Comments
Member 7896310 4-May-11 11:13am    
It's not homework. i'm trying to learn it by myself =)
So what i do is i make a string with the number of #'s i want and then make the loop last as many letters there are in pounds string..

Then it writeline(pounds.[b]substring(i)[/b]);

That part i did not understand. Correct me if i'm wrong... but does pounds.substring(i), write the value of i, in letters of pounds?
Or what does substring mean?
yesotaso 4-May-11 11:16am    
Mathematical terms: Let a string be "WELCOME" then it may be considered as a set of letters 'W' 'E' 'L' 'C' 'O' 'M' 'E' a substring is a subset of this set like "ELCO"
which can be expressed as subtring starts 2nd char and length is 4 chars.
the statement in question means it starts at 1st char(because there is 1 number given starting letter is by default 1st one) and ends at i th char where "i" is the variable which represents the length of each line in the picture you sent.
#realJSOP 4-May-11 11:19am    
Look up string.Substring in google, and you'll see why this will work. The overload I'm using will return a substring of the original starting at the specified index (i in my example).
yesotaso 4-May-11 11:13am    
Improvement:
x = 10;
string pounds = new string('#',x);
:-)
Member 7896310 4-May-11 11:18am    
So that gives the ammount of '#' as a factor of the x value?
try this :)

C#
static void Main(string[] args)
        {

            for (int y = 1; y <= 10; y++)
            {
                for (int x = 10; x >= y-1; x--)
                {
                    Console.Write("#");
                }
                Console.WriteLine();

            }
            Console.WriteLine("Oh Herro!");
            Console.ReadLine();

        }
 
Share this answer
 
Comments
Member 7896310 4-May-11 11:39am    
This was exactly the one i was looking for! The lesson said "that the inner loop should use values from the outer loop".. Thank you very much!!!
ambarishtv 4-May-11 11:58am    
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900