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');
// 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;
}
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.