displays the character ch on the stdout device (screen) consecutively n times

Write a C++ function display prototyped by
int display(char ch, int n);
that displays the character ch on the stdout device (screen) consecutively n times if n>0 and displays nothings if n≤0. When n>0 and ch is not the blank character, the function will also display an additional newline at the end. The function display returns the actual number of characters (excluding the possible newline at the end) displayed.
Write a driver program, making use of the above specified function display, that line by line repeatedly displays the character pattern

Please view the image located at .
http://imageshack.us/f/14/35101332.jpg/

until a given numer of non-whitespace characters are displayed. In other words, the program will first ask the user to enter the total number, say target, of non-whitespace characters to be displayed, and then it will repeatedly display the above pattern until exactly target non-whitespace characters are displayed. For instance, if target is entered as 150, then the program will produce the following output (containging exactly 150 non-whitespace characters) afterwards:

Please refer to the image located at :
http://imageshack.us/f/256/48054752.jpg/

Needing some help with this, i will also post up my code that i have done thus far please help.


My code so far as to what i have done and am missing quite a bit.

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
#include <iostream>
using namespace std;
int main() 
{
    int n;
    char char_a, char_b;
    char_a;
    char_b;
    cout << "Enter value for n " << endl; 
    cin >> n;
    cout << "Enter values for the character, a and b " << endl;
    cin >> char_a >> char_b;
    void display (char, int);    
     char_a; //star = 42;
     char_b; //pls = 43;     
     for(int i =0; i<n; i++){
             display(char_a, i);
             cout << endl;
     }
     for(int i = n -1; i>-1; i--){
             display(char_b, i);
             cout << endl;
     }
     system ("pause");
     return 0;
}


void display(char c, int n) {
     char blank = 32;
    for (int i =0; i< n; i++){
        cout << blank;
    }
    for (int i=0; i < n+1; i++){
        cout << c;
    }
}
Last edited on
Topic archived. No new replies allowed.