Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-29-2005, 07:17 PM   #1 (permalink)
josh2two
Registered User
 
Join Date: Sep 2005
Posts: 22
josh2two is on a distinguished road
Printing a triangle

Ok i figured out how to print this triangle , Now I can't figure out how to print the same triangle in reverse, so the 2 stars would be on the bottom.
-Printing a triangle with a step of 2 and a height of 5 would loop like:
**
****
******
********
**********

void print_triangle(int step, int height) // prints a triangle with a step and height
{
for( int i = 1; i <= height; i++)
{
for( int j = 1; j <= step * i; j++)
{
cout << "*";
} // end of nested for
cout << endl;
} // end of outer for loop
} // end of print_triangle function
josh2two is offline   Reply With Quote
Old 11-30-2005, 02:27 PM   #2 (permalink)
josh2two
Registered User
 
Join Date: Sep 2005
Posts: 22
josh2two is on a distinguished road
please help
josh2two is offline   Reply With Quote
Old 11-30-2005, 02:34 PM   #3 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Sorry to say this but why did you choose C++ to start with? The type of thinking should suit the student if possible but the factor "fun" is perhaps even more important. You should learn to have fun with this. Do it this way:

Fiddle with redhead's algorithm and see what the result is. Do this until you truly "see" how it works. Once you did that, your next assignment (triangle reversal) should be easy.
__________________
Valmont is offline   Reply With Quote
Old 11-30-2005, 03:55 PM   #4 (permalink)
josh2two
Registered User
 
Join Date: Sep 2005
Posts: 22
josh2two is on a distinguished road
I have to take the class because it is required in our engineering program. It is very stupid because i will never use this after this one class. Our college is probably going to take this class out of the engineering requirements, but they just don't know when they are going to do that.
josh2two is offline   Reply With Quote
Old 12-01-2005, 01:45 AM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Quote:
It is very stupid because i will never use this after this one class.
Oh boy, I can't recall how many times I've thought "I'll never use this again" and how wrong I've been.
It might not be the exact same contence you're using, but rather skills aquired while fiddling with a solution to a simple problem like this one.

Let me give you a fast 101 on Comp. Sci. the essence in solving programming-problems, is systematicaly to break it down into small sub-problems which in term can be answered with a simple yes/no(1/0) request.
Eventho, saying it like this sounds as if I'm just rambling, you might think "How can that work in real life" But think about it, in how many other situations will a systematicaly splitting of the entire problem into sub-problem, that are simplified steps towards the common goal of solving the orriginal problem, help you solve your problem?
You'd be supprised that it virtualy suits every problem encountered in your daily life.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-01-2005, 06:35 AM   #6 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 733
DJMaze is on a distinguished road
Comp. Sci. is nothing more then mathematics. If you were bad in maths on school i understand you hate it since maths is nothing more then plain thinking: 1 = 1 and don't think why.
But as redhead says, in this case maths is used to solve problems although on first you think it has nothing to do with real life, it realy does.

The thing is that your "straight thinking" is tested like:

You stand for a door and want to the other side:
1. open the door
2. ask someone how to open the door
3. break in
4. walk around to see if there's another entrance

Some people are hard/stressed thinkers that think about many options to get to the other side. A clean mind just opens the door, nothing more nothing less.

It's just a way of thinking, don't hate it

Hint: the oposite of ++ is -- like: for (i = height; i > 0; i--)
DJMaze is offline   Reply With Quote
Old 12-01-2005, 10:26 PM   #7 (permalink)
josh2two
Registered User
 
Join Date: Sep 2005
Posts: 22
josh2two is on a distinguished road
i already tried the i-- and the program prints *'s and never stops
josh2two is offline   Reply With Quote
Old 12-01-2005, 10:27 PM   #8 (permalink)
josh2two
Registered User
 
Join Date: Sep 2005
Posts: 22
josh2two is on a distinguished road
never mind i got the progam to work, thanks everyone
josh2two is offline   Reply With Quote
Old 12-02-2005, 03:21 AM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Quote:
If you were bad in maths on school i understand you hate it since maths is nothing more then plain thinking: 1 = 1 and don't think why
Not quite, the secret in math, is to look at your problem and see if theres parts of it you have seen befor and thus knows a viable solution to.

Given a hyperthetic mathmatical prof, you might take a look at it, and all of a sudden realise one part of it is an alternating taylor seequence, which can be expressed by the sin() function, then you exchange every instance of that in the orriginal expression.
After looking at the altered expression once again, you might realise it is infact some form of deriviation from a tan() derived function, so you perform the integrale on the expression and realise that it's just a fancy way of calculating angles in a pentagon.

You might compare it to my former way of thinking with splitting everything up into smaller sub-problems and solve those, but math isn't quite the exact same as Comp. Sci. Altho alot of the brainwork required there is very usefull in Comp. Sci. aswell.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-03-2005, 11:09 PM   #10 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Quote:
you might take a look at it, and all of a sudden realise one part of it is an alternating taylor seequence, which can be expressed by the sin() function, then you exchange every instance of that in the orriginal expression.
After looking at the altered expression once again, you might realise it is infact some form of deriviation from a tan() derived function, so you perform the integrale on the expression and realise that it's just a fancy way of calculating angles in a pentagon.
You wouldn't believe how many times this happens to me while looking at my alphabet soup.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Platform Independent Printing Solutions for C++ laalitseth Standard C, C++ 3 04-15-2005 01:14 AM
Printing Embedded Icons freesoft_2000 Java 0 12-29-2004 10:25 PM
Printing freesoft_2000 Java 0 11-27-2004 12:19 PM
Problem printing, please help me laurence10 Java 0 03-11-2003 05:26 PM


All times are GMT -8. The time now is 12:17 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting