We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,901 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

c++ while loops problem

Hi friends

i had a assignment to make this c++ program

output

f e d c b a 
  e d c b a 
    d c b a
      c b a 
        b a
          a

i have created this program using this code

# include <iostream.h>
  # include <conio.h>
  void main(void)
  {
char x[6];
  int m=0;
  int n=70;
  int z=0;
  int p=32;
  int b=1 ;
  while(m<6)
  {
  x[m]=n;

  n=n-1;
  m++;

  }
 while(z<6)
  {

  int f=0;
    while(f<6)
    {

    cout<<x[f];
    x[z]=p;
    cout<<x[z];
    f++;
    }
cout<<endl;
    z++;
    }

    }




but its output is 




    f e d c b a 
        d c b a
          c b a 
            b a
              a

if somebody help me than i will be very thankful to you

Regards

2
Contributors
1
Reply
25 Minutes
Discussion Span
7 Months Ago
Last Updated
2
Views
Manchala
Newbie Poster
5 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You don't need arrays or while loops. Just use three simple for loops. The first counts the number of rows, which is 6. The second displays space(s) to move the cursor on the screen, and the third displays the letters in reverse order that they appear in the alphabet.

loop counts from 0 to 6 // you need 6 rows of data on the screen
   loop counts from 0 until it reaches the value of first counter
      display a space
   loop counts from 'F' - value of first counter, down until it reaches 'A'
       display char value of the counter
Ancient Dragon
Achieved Level 70
Team Colleague
32,124 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 69

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0575 seconds using 2.67MB