Previous program being used, that works fine. I have tried placing my break statements in various places within the programming and cannot get it to run that specific triangle that was entered so that I can enter the letter 'q' to quit. Program is to execute continuously until the user enters 'q' to quit.
Request if for one function that accepts the user input, 2nd prints the ascending, 3rd prints the descending triangle. Since my previous program did that I thought I would just have to add the break, while true statement, and a flag for quiting. It is not working. So I know I am doing something wrong.

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

int main()
{   
    char letter = ' ';

    /This program will display a triangle in ascending or descending order
    cout << "Enter (A)scending or (D)escending: " << endl;
    cin >> letter;

    if(letter == 'A' || letter == 'a')
    {
        int x = 0;
        while(x <= 9)
        {
            int y = 0;
            while(y <= x)
            {
                    cout << "*";
                    y++;
            } //end while
            cout << "\n";
            x++;
        }//end while
    }// end if
    else if(letter == 'D' || letter == 'd')
    {
        int x = 9;
        while(x > -1)
        {
            int y = 0;
            while(y <= x)
            {
                    cout << "*";
                    y++;
            } //end while
            cout << "\n";
            x--;
        }//end while
    }
    else
    {
    cout << "Invalid input.";
    }
        getch();
        return 0;
    }

To get out of loop I have used the following macro:

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

if KEY_DOWN(vk_q) ...

vk_q is simply the ascci value of q

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.