Start New Discussion within our Software Development Community

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

This article has been dead for over six months. Start a new discussion instead.