![]() |
| ||
| for and while HELP hiz, well i have a question regarding to for and while loop i want to create such a triangle with "*" * * * * * * * * * * (its not right angle triangle, its equilateral triangle) and 2nd thing, what if i want the USER to put the line numbers (upto 30) Thnx MnMustafa |
| ||
| Re: for and while HELP ||||||* ||||*||* ||*||*||* *||*||*||* like this but without "|" |
| ||
| Re: for and while HELP Read this http://www.daniweb.com/forums/announcement8-2.html Make an effort. Read this http://www.daniweb.com/forums/announcement8-3.html and post your attempt. |
| ||
| Re: for and while HELP well thnx for those articles, but this isnt my homework or something, i m trying to do this since 2 days, i am new, so ofcourse i need some help. well here is the program i wrote which has 7 errors # include <iostream> thnx |
| ||
| Re: for and while HELP The first thing you need to do is get the number of lines to print, using cin. First, create a variable to hold the number of lines, then read it in from the user. An example would be int count; |
| ||
| Re: for and while HELP well sir, actually the CIN is 2nd part of my question!! :) i just want to write a program if i want to create 4 lined equilateral triangle.. |
| ||
| Re: for and while HELP Use for loops to print the stars, the spaces, etc. The standard for loop structure is one of the following two for( int i = 0; i < numberOfTimes; i++ ) for( int i = 1; i <= numberOfTimes; i++ ) for loop number of lines { for loop spaces} Edit: BTW, the number of spaces to print is equal to the TotalNumberOfLines - CurrentLineNumber The number of stars to print is equal to the CurrentLineNumber |
| ||
| Re: for and while HELP Ok so lets 'draw' one by hand and then figure out how to get the computer to do what we did. (I'm going to use '.' instead of ' ' so you can see them.) Ok so in my head, I start with the base of the triange as that determines how big it will be: *.*.*.* Then I just add the lines above it: ...* Is that what you wanted? So, for a 4 row triangle, the first row must be indented 3 spaces, the next 2 spaces, the next 1 space and the last line isn't indented at all. The first line has 1 star, the second 2 stars seperated by a space, the third 3 stars with spaces and the last 4 stars with spaces. Do you see a pattern here that you might be able to exploit? |
| ||
| Re: for and while HELP thnx people |
| ||
| Re: for and while HELP |
| All times are GMT -4. The time now is 5:18 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC