ANY IDEA?

Ok here's the thing.. i need to make a program which asks the user for a number and a char.
This is fine once u have the # and char you must do this figure

*
* *
* * *
* * * *
* * *
* *
*

The max width of the figur is the number and the char is whaat the figure is done.
so if i enter 3 & R it should display

R
R R
R R R
R R
R
any idea? im supposed to use for, while and do..while for this
im not seeking for the answere only ideas or tips
im desperate :S thanks
dam it was supposed to display a rhumbus :S well got the idea?
This is a hint in the right direction, but it should be enough to get you started. There are a number of ways to approach this problem, but you should be able to figure out what to do from here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>

int main(void)
{
  unsigned int num; // this is the number input by the user
  // it will tell the program the width of the rhombus

  char output; // this is the character they want to display
  
  // the rhombus array holds the shape you wish to draw
  // it does not have to be exact, but it should be close
  // you can adjust the spacing to make it more angular
  // or more round, depending on your requirements

  char rhombus[37] =
            {78,
          111, 32,
       111, 110, 101,
      32, 119, 105,108,
    108, 32, 100, 111,32,
  121, 111,  117, 114,  32,
   104,111, 109, 101,119,
     111, 114, 107, 32,
       102, 111, 114,
         32,121,111,
           117, 46
              };
  
  std::cout << "Please enter the maximum width: ";
  std::cin >> num; // this gets number input from the user

  while(std::cin.get()!='\n') // here is the WHILE loop you mentioned
    continue; // this continues the program

  std::cout << "Please enter the character to use: ";
  std::cin.get(output); // this gets the character input from the user

  // now you have the user input, so you plug the
  // character into the rhombus array, and then you use a
  // FOR loop to display each line by the number of times
  // that the user input into the "num" variable.

  for(int j = 0; j<num; j++) // this will loop the number of times
  { // that the user input into the "num" variable
    for(int i = 0; i<37; i++) // fills rhombus with the character
      std::cout << rhombus[i]; // display the character
    std::cout << std::endl; // output a newline \n to start next row
  }

  return 0; // program finished
}

Last edited on
Topic archived. No new replies allowed.