Thank you in advance for anyone who is willing to help me. Can someone give me the answers and briefly explain what you did? I have been stuck and frustrated with these questions for about a week now, so I'm asking for help. There are two questions that I need help with and they are:

1.) Write a program to print the hollow diamond of stars (*), ask the user to enter an odd number as the height. For example, if user enters height as 7, output will look like:

      *   * 
    *      * 
   *        * 
    *      * 
     *   * 

2.) Write a program that asks the user to type positive integers. When the user types a negative value the program writes ERROR and asks for another value. When the user types -1 that means that the last value has been typed and the program must write the average of the positive integers. If the number of typed values is zero the program writes 'NO AVERAGE'.

You haven't shown us what you have done to solve this yourself, but for the first one, for problems of this type I suggest you work with a specific example. Take a number, like 7, then write out the number of each character that needs to be output per line

3 spaces plus 1 asterisk
2 spaces plus 1 asterisk plus 1 space  plus 1 asterisk
1 space  plus 1 asterisk plus 3 spaces plus 1 asterisk

Then figure out what loop(s) you need to generate those numerical values. Once you have this for a specific number you can generalize it for any odd number.

The second question suffers from spec error (and was asked by another user). A negative number both generates an error and causes an average to be calculated. Rewrite the spec.

commented: Thank you, I got the question done yesterday. +0

The hollow diamond is about distance from center column and distance from center row; their sum s/b half the height to print. In this case, 3. So:

for ( int c = 0 ; c < 7 ; c++ ){
  for ( int r = 0 ; r < 7 ; r ++ ){
     If ( r + c == 3  || r - c == -3 || r + c ==  9 || r - c == 3 ){
        cout << ‘*’ ;

     cout << ‘\n’ ;
// r + c goes from upper right to lower left
// r - c  goes from upper left to lower right
commented: On Daniweb we strive to help. Doing someone's homework for them is not helping. -3

How do you teach those who fall off the official wagon?

@DG, I tend to not worry about when the student gets the homework done for them. Why? Next week another assignment and they didn't learn from last week so the climb gets harder and harder. Eventually they fail. Or worse they learn "this is how you program today. You ask and let others write the code for you."

PS. Added with edit. Now that this code is on the web, a prof could use one of the many plagiarism checkers and blammo. They get a failing grade on this assignment.

commented: In my defense, I do not have a proffesor for my C++ for Engineers course. I only have my TA to teach me, and he is not great at explaining. +0

How do you teach those who fall off the official wagon?

To use your metaphor, what kind of lesson is giving a drink to an alcoholic? We don't teach people the value of work by doing it for them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.