446,227 Members | 1,269 Online Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

# class project

 P: 4 I need to know how i could right a program that will take as input a character and an integer. If the integer is even, then add one to it. Using the for loop to make the output a diamond composed of a character and as wide as the int. e.i. Enter a character and an integer: @ 4 @ @@ @@@ @@@@ @@@ @@ @ I would really appreciate it i've been trying to figure it out for the entire weekend Oct 3 '06 #1
4 Replies

 P: 27 Try this out, let me know if it does what you want. Wasn't sure about the adding one to an even number thing, I might have been mis-reading your question, but this should start you out: Expand|Select|Wrap|Line Numbers #include    using namespace std;   int main(int argc, char* argv[]) {     char symbol;     int numPrints, i, j;       cout << "Enter symbol: ";     cin >> symbol;     cout << endl << endl;     cout << "Enter Integer: ";     cin >> numPrints;     cout << endl << endl;       for (i = 1; i <= numPrints; i++)     {         for (j = 1; j <= i; j++)         {             cout << symbol;         }         cout << endl;     }       for ( i = numPrints - 1; i > 0; i--)     {         for (j = i; j > 0; j--)         {             cout << symbol;         }         cout << endl;     }       return 0; }   Anthony Oct 3 '06 #2

 100+ P: 293 He didn't use (code) tags, so the whitespace was not preserved. He meant Expand|Select|Wrap|Line Numbers    @   @@@  @@@@@ @@@@@@@  @@@@@   @@@    @ You need two loops, one to do the top half of the diamond, one to do the second half of the diamond. Then each loop needs to first print some spaces, then print that symbol several times. Expand|Select|Wrap|Line Numbers string(numberOfSymbol,symbol) Prints the (char)symbol (int)numberOfSymbol times. I'll pseudocode the printing part. Expand|Select|Wrap|Line Numbers // Top half numSymbols = 1; while(numSymbols < maxSymbols) {   numSpaces = // A function of numSymbols and maxSymbols   cout << string(numSpaces,' ');   cout << string(numSymbols,symbol) << endl;   numSymbols += 2; } // Bottom half while(numSymbols > 0) {   numSpaces = // The same function of numSymbols and maxSymbols   cout << string(numSpaces,' ');   cout << string(numSymbols,symbol);   numSymbols -= 2; } Oct 3 '06 #3

 P: 27 Ahh, I see - sorry for the confusion. Didn't realize the absence of code tags. Thanks, D_C, for clearing that up, and answering the question. Oct 3 '06 #4

 P: 4 thank you for your help Oct 4 '06 #5 