• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

printing the rombus

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone C:
If anything, I'm Russian and I know my English is not perfect, sorry


I need to do the program, printing the rombus of *, + or # using operator SWITCH. The problem is that I don't know how to directly organize the output symbols. This is my poor (in all senses) code:






So how to make it work? How to print rhombus?

A compiler also marks the 17th line as error.
I will be happy to get your explanations. Thank you
 
Marshal
Posts: 80939
521
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
So, you want to printThat is a common problem, and the solution is similar both in C++ and Java®. Remove the choice about which symbol to print; that is getting in your way. When you get the rhombus printed, then you can put the choice back.
You shou‍ld move most of that code out of the main function. Just as in Java®, that is intended for starting the application, not for the whole application. I suggest the following stages might help:-
  • 1: Set up a loop to print 1 2 3 4 5
  • 2: Enhance that loop to run from 1...n
  • 3: Enhance that loop to print 1 3 5 7...n
  • 4: Enhance the loop to print 1 3 5 7...n...7 5 3 1
  • Hints:-
    1: The loop will run from 1 to 2n − 1. But maybe not 2n − 1 iterations.
    2: You can create max and min functions, if they are not already available and work out how many to print with subtraction.
  • 5: Create a loop to print n - 1...4 3 2 1 0 1 2 3 4...n - 1
  • 6: Put the two loops together to print 4 1, 3 3, 2 5, 1 7, 0 9, 1 7, 2 5, 3 3, 4 1
  • 7: Work out which of those numbers means spaces and which means print a symbol
  • This is how I would write min in C; max is very similar:-Note: the height and width of a rhombus are the same.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic