inverse pyramid and diamond

Hello:
I'm suppossed to create a triangle, inversed pyramid and a diamond using a "magic word". The magic word is any word that the user decides to input..
I have the following code. but when i run it, step2 is not processed at all. The program only runs step one, not step two.
I'm suppossed to use the while loop.
Can't seem to figure out how to do the inverse pyramid and diamond.
Some help would be gratly appreciated.

My program looks:

#include<iostream>
#include<string>
using namespace std;

int main (void)
{
// Input command
string magicWord;
cout << "Enter magic word: ";
cin >> magicWord;
cin.ignore(99,'\n');

cout << endl;
cout << "step one: " <<endl;
cout << endl;
//Initialization
int suffixStart = 0;
int suffixLength = magicWord.length();

// end test: finished when the current suffix is empty
while (suffixLength >0)
{
// Loop body: output suffix extracted from word
string suffix = magicWord.substr( suffixStart, suffixLength );
cout << suffix << endl;

// step: update suffix location to exclude first char
suffixStart = suffixStart + 1;
suffixLength = suffixLength - 1;
}

cout << endl;
cout << "step two: " <<endl;
cout << endl;

int suffixStart1 = 0;
int suffixLength1 = magicWord.length();
while (suffixLength >0)

{
// loop body: output suffix extracted from word
string suffix = magicWord.substr( suffixStart1, suffixLength1 );
cout << suffix << endl;

// step: update suffix location to exclude first char
suffixStart = suffixStart + 1;
suffixLength = suffixLength - 1;

}

cout <<endl;
cout << "final step:" <<endl;
cout << endl;
// Initialization

// endgame
cout << endl << "Press ENTER to finish...";
cin.ignore(99,'\n');
return 0;
}


An example of outcome is :

Enter a magic word: caroline

step one:

caroline
aroline
roline
oline
line
ine
ne
e

step two:

carolinecaroline
carolinaroline
caroliroline
carololine
caroline
carine
cane
ce

final version:

ce
cane
carine
caroline
carololine
caroliroline
carolinaroline
carolinecaroline
carolinaroline
caroliroline
carololine
caroline
carine
cane
ce

Press ENTER to finish...
Last edited on
You are almost there - I just have two suggestions:

1. Format your code inside code tags so it's legible.

2. Learn how to use your debugger. You will find the answer to this kind of question much faster by stepping through line-by-line and displaying variable values. Also, knowing how to use the debugger will save you when you get to much harder debugging problems than this one.
Last edited on
Thnx for the reply.
Topic archived. No new replies allowed.