I need to write a program that inputs an integer and a character, and outputs a symetrical triangle composed of the character that has the interger of new lines. I can only use 'while' loops at this stage of the course, and I know it has to be nested 'while' loops. I can not use 'for/next' loops. I have done this before in VB6, so I am somewhat exasperated that I can not even get past firstbase with this same problem in C++. And I like C++, strangely enough. Ive spent close to 20 hours trying to figure it out and just cant ;0

the display needs to look something like(minus the -'s that i had to use here as a placeholder):

-----$
----$$$
---$$$$$
--$$$$$$$
-$$$$$$$$$

<< moderator edit: spaces are preserved using [co[u][/u]de][/co[u][/u]de] tags >>

$
    $$$
   $$$$$
  $$$$$$$
 $$$$$$$$$

I set a variable to the same as the inputed integer and i did
k-- to decrease the space by one every time, but i dont know how i should display more than 1 character per line..
---------------------------------------------------------
Any suggestions would be greatly appreciated.

Recommended Answers

All 3 Replies

Member Avatar for iamthwee

U know how 2 convert a for loop into a while loop now don't u?

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


int main(void)
{
    cout<<"enter a integer";
    int b;
    cin>>b;

    cout<<"enter a symbal";
    char s;
    cin>>s;

    int space=b;

    int k=1;
    for(int i=0; i<b; i++)
    {

        for(int j=0; j<space; j++)
        {
            cout<<" ";

        }
        space--;


        for(int m=0; m<k; m++)
        {

        cout<<s;
       }  
       k=k+2;   
        cout<<"\n";
    }

   system("pause");             
}

Don't worry yourself about creating the spaces and aligning into a triangle.... Thanks to C++ you can set the width and fill character of the output ;)

Thanks guys for the help. while loops can get confuseing as hell with all the brackets and everything.

Thanks again guys :)
Kisvirag

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.