need some help C# console program

Started by
15 comments, last by jpetrie 16 years, 3 months ago
well for my assignment, i have to allow the user to input 2 values:(1)a character to be used for printing the triangle and the size of the peak for the triangle. example, if the user uses # for the character and 6 for the peak the following should be printed # ## ### #### ##### ###### ##### #### ### ## # i have no problem with the printing the character,but how would i go about going from the number entered for the peak to actually printing the triangle withthe appropriate amount???
Advertisement
this is obviously a homework assignment, and gamedev has a policy that we cannot solve homework assignments for you.

To point you in the right direction (or at least 1 of the possible ways to solve it):

Use loops.
not a homework assignment, its a review assignment

and i thought it was loops, but still im drawing a blank on as to how to print it out im thinking something along the lines of while(character !> peak)

but i dont get how to print the character once, then go to the next line and print it again
Quote:Original post by durtyduval
not a homework assignment, its a review assignment

and i thought it was loops, but still im drawing a blank on as to how to print it out im thinking something along the lines of while(character !> peak)

but i dont get how to print the character once, then go to the next line and print it again

Well then it looks like you need more practice since this should be pretty easy if you've been doing any amount of programming since it pops up all the time when you are trying to do any sort of grid or barchart like my sample program in C++ here I did in my first C++ class:
#include <iostream>using std::cout;using std::cin;using std::endl;int main(){	int num, num2, num3, num4, num5; // for reading 5 numbers	cout << "***Simple bar chart program***\n\n";		// read first number		cout << "\nPlease enter a number from 1 to 30:";		cin >> num;		// read second number		cout << "\nPlease enter another number from 1 to 30:";		cin >> num2;		// read third number		cout << "\nPlease enter another number from 1 to 30:";		cin >> num3;		// read fourth number		cout << "\nPlease enter another number from 1 to 30:";		cin >> num4;		// read fifth number		cout << "\nPlease enter another number from 1 to 30:";		cin >> num5;		cout << "\nThe numbers you entered in bar chart form:\n\n";		// output asterisks for first number				for(int i = 1; i <= num; ++i)			cout << "*";		// need newlines in between		cout << '\n';		for(int i = 1; i <= num2; ++i)			cout << "*";		cout << '\n';		for(int i = 1; i <= num3; ++i)			cout << "*";		// need newlines in between		cout << '\n';		for(int i = 1; i <= num4; ++i)			cout << "*";		cout << '\n';		for(int i = 1; i <= num5; ++i)			cout << "*";		// need newlines in between		cout << "\n\n";	return 0;}

[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
This is the exact reason why GameDev folks do not help with homework. Why would we want to work with someone that can't do this basic homework?

theTroll
Quote:Original post by daviangel
Quote:Original post by durtyduval
not a homework assignment, its a review assignment

and i thought it was loops, but still im drawing a blank on as to how to print it out im thinking something along the lines of while(character !> peak)

but i dont get how to print the character once, then go to the next line and print it again

Well then it looks like you need more practice since this should be pretty easy if you've been doing any amount of programming since it pops up all the time when you are trying to do any sort of grid or barchart like my sample program in C++ here I did in my first C++ class:
*** Source Snippet Removed ***


its just that the concept of it doesnt make sense to me, i cant connect the dots

im sure its a simply solution, and im not askign for any1 to do it for me, i dont like that but i am asking for a little help in the right direction...i just cant get a grasp on this situation
Quote:Original post by daviangel
Quote:Original post by durtyduval
not a homework assignment, its a review assignment

and i thought it was loops, but still im drawing a blank on as to how to print it out im thinking something along the lines of while(character !> peak)

but i dont get how to print the character once, then go to the next line and print it again

Well then it looks like you need more practice since this should be pretty easy if you've been doing any amount of programming since it pops up all the time when you are trying to do any sort of grid or barchart like my sample program in C++ here I did in my first C++ class:
*** Source Snippet Removed ***


see now i started and so far this is what i got, once i get to the loop to print it out i get stuck and i have no idea how to do it, im sure once i figure it out ill feel dumb but im really drawing a blank, any1 got any hints?

using System;using System.Collections.Generic;using System.Text;namespace PeakTriangle{    class PeakTriangle    {        static void Main()        {            int peak;            string stringPeak;            string stringCharacter;            Console.WriteLine("Please enter the character you want to print:");            stringCharacter = Console.ReadLine();            Console.Clear();            Console.WriteLine("Please enter the peak:");            stringPeak = Console.ReadLine();            Console.Clear();            peak = int.Parse(stringPeak);            for (int count = 1; count &lt; peak; ++count)            {                            }        }    }}
Go one step at a time. First, figure out how to write one line of characters of any length. Second, figure out how to write the upper half of the pyramid. Third, figure out how to build the whole pyramid.

BTW, I strongly recommend that you avoid looking at other people's code and figure this out for yourself. Using loops for these kinds of things is so fundamental that you should really understand it top to bottom.
If you look at the output you need to generate you will notice that it is two dimensional.
Two dimensions is often solved using nested loops. You might want to look into that.
I'm going to build off of Gage's idea of giving you sub-questions to work with.

1. How do you print a line of characters that is X long?
2. How do you print X lines of one character each?
3. How can you then print X lines of X characters each?
4. How can you print X lines, each line having one more character than the last, starting at one character?
5. How can you make this into a triangle?

This topic is closed to new replies.

Advertisement