Jump to content
  • Advertisement
Sign in to follow this  
durtyduval

need some help C# console program

This topic is 3986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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???

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;
}


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)
{

}

}
}
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 3986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!