i can't think of the logic of this machine problem..
the problem statement is this..

Using loop, write a program that will ask the user to enter a character for left or right. Then, the user will enter a number. The program should generate a ladder of x wherein the level depends on the number entered and the character should dictate whether it faces right or left.

Sample:

Character is r
Number is 3

Output
X
XX
XXX

Character is r
Number is 6
X
XX
XXX
XXXX
XXXXX
XXXXXX

character is l
number is 5
X
XX
XXX
XXXX
XXXXX <this one is facing left>


pls. help me..

to make one line of your ladder:

#include <string>

std::string make_line( char X, std::size_t num_chars,
                       std::size_t num_spaces_on_left )
{
  const char space = ' ' ;
  return std::string( num_spaces_on_left, space ) +
         std::string( num_chars, X ) ;
}

to make one line of your ladder:

#include <string>

std::string make_line( char X, std::size_t num_chars,
                       std::size_t num_spaces_on_left )
{
  const char space = ' ' ;
  return std::string( num_spaces_on_left, space ) +
         std::string( num_chars, X ) ;
}

thanks.. but i need the syntax that using only loop and if-else..

So read your book / lecture notes on loops and conditionals, and give it your best shot.

Just dumping your assignment without a line of code very seldomly gets you what you want (the answer on a plate).

This article has been dead for over six months. Start a new discussion instead.