473,378 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Loop Problem--help

40
I want to make an output like a Christmas Tree

but...my code shows only half of it...
*
**
***
****
*****
What's wrong with my loop?

for(x=1;x<=5;++x){
for(y=0;y<x;++y){
cout<<"*";
}
cout<<"\n";
}
Mar 7 '07 #1
6 2021
horace1
1,510 Expert 1GB
you need to print spaces before the *, 5 on first line, 4 on second, etc so you get the triangle indented
Mar 7 '07 #2
bitong
40
you need to print spaces before the *, 5 on first line, 4 on second, etc so you get the triangle indented
just a follow up question...does C++ have a gotoxy(col, row) like in Turbo C? if not what does C++ have in lieu of the col, row in turbo c..thanx for the reply
Mar 7 '07 #3
Ganon11
3,652 Expert 2GB
C++ doesn't have this, but if you look up the conio header file, you can use the goto(x, y) function normally.
Mar 7 '07 #4
bitong
40
you need to print spaces before the *, 5 on first line, 4 on second, etc so you get the triangle indented
where am i going to put the spaces? before the second for loop or after the two loop? am i going to use "\t"?
Mar 7 '07 #5
horace1
1,510 Expert 1GB
where am i going to put the spaces? before the second for loop or after the two loop? am i going to use "\t"?
Expand|Select|Wrap|Line Numbers
  1. for(x=1;x<=5;++x){
  2.   <<<   print spaces here!
  3. for(y=0;y<x;++y){
  4. cout<<"*";
  5. }
  6. cout<<"\n";
  7. }
  8.  
to print the spaces you would use a for() loop which decrements (unlike the * which increments)
Mar 7 '07 #6
bitong
40
Expand|Select|Wrap|Line Numbers
  1. for(x=1;x<=5;++x){
  2.   <<<   print spaces here!
  3. for(y=0;y<x;++y){
  4. cout<<"*";
  5. }
  6. cout<<"\n";
  7. }
  8.  
to print the spaces you would use a for() loop which decrements (unlike the * which increments)
ok..thanx a lot for the replies.. =)
Mar 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
5
by: !TG | last post by:
I currently use Do while loop, but I'd rather use a For Loop though I have never gotten the hang of them. Would some one please be so kind as to show me how to loop through a recordset.
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.