473,394 Members | 1,813 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,394 software developers and data experts.

Issue in For loop

32
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iostream>
  3. #include <string>
  4. #include<cctype>
  5.  
  6. using namespace std;
  7. int main()
  8. {
  9.     int i,j,k;
  10.  
  11.  
  12.  
  13.     for(i=0; i<8; i++)
  14.     {
  15.        for(j=0;j<i;j++)
  16.         {
  17.             cout<<'\t'<<"*";
  18.  
  19.              }
  20.  
  21.            for(k=0;k < 16; k= k+2){
  22.         cout<<endl;
  23.  
  24.    }
  25. }
  26.  for(i=7; i>=0; i--)
  27.     {
  28.         for(j=i;j>=0;j--)
  29.         {
  30.             cout <<'\t'<<"*";
  31.  
  32.              }
  33.  
  34.            for(k=14;k >0; k= k-2){
  35.         cout<<endl;
  36.  
  37.     }
  38. }
  39.     system("PAUSE");
  40.     return 0;
  41.  
please guys, i have done that loop and i want the ouput to look like this
*
* *
* * *
* *
*
i want the first star to be in the middle and then in the second row two stare also in the middle uder the first star which means the first star look in between then ... i hope u can help me guys
Dec 17 '07 #1
3 1052
scruggsy
147 100+
please guys, i have done that loop and i want the ouput to look like this
*
* *
* * *
* *
*
Is that really how you want it to look, or do you want it to look like this:
Expand|Select|Wrap|Line Numbers
  1. .
  2.     *
  3.    * *
  4.   * * *
  5.    * *
  6.     *
...or something along those lines?

If so, you will need to output enough whitespace before each set of stars in order make them line up. You should be able to calculate the number of tabs or spaces to use based on the value of the loop variable: more spaces for lower values, fewer spaces for higher values.
Dec 17 '07 #2
samimmu
32
Is that really how you want it to look, or do you want it to look like this:
Expand|Select|Wrap|Line Numbers
  1. .
  2.     *
  3.    * *
  4.   * * *
  5.    * *
  6.     *
...or something along those lines?

If so, you will need to output enough whitespace before each set of stars in order make them line up. You should be able to calculate the number of tabs or spaces to use based on the value of the loop variable: more spaces for lower values, fewer spaces for higher values.

yeah exactly as you said. i should output like the way you said.... i wish i can help by writing up on that code...
Dec 17 '07 #3
scruggsy
147 100+
yeah exactly as you said. i should output like the way you said.... i wish i can help by writing up on that code...
Yeah, no one will write the code for you.
But if you post your code and explain the problem we can help you figure out how to get it working.
Dec 17 '07 #4

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

Similar topics

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) {...
4
by: Ryan Ternier | last post by:
I'm having an issue with an inner loop. Here's the basic Code: For each......{ //Do code here //start other loop For each....{
102
by: tom fredriksen | last post by:
Hi I was doing a simple test of the speed of a "maths" operation and when I tested it I found that removing the loop that initialises the data array for the operation caused the whole program to...
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: 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?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.