my assignment is to make a triangel like so:
*
**
***
****
*****

I have done so but cannot get my command window to stay open. It pops up and closes right back out. heres my code can anyone help?

#include <iostream>

int drawBar(int);

int main()
{
     std::cout << std::endl << "Let's Draw a triangle!\n";

     //determine how many lines will be drawn
     int triangleBase = 0;

     //draw the triangle 
     for (int i = 5 ; i >= triangleBase ; i--) {
         drawBar(i);
     }

     return 0;
} //end main

int drawBar(int barSize) {
//draws a line of asterisks
//the number of asterisk drawn equals barSize

     int theCounter = 5;
     while (theCounter >= barSize) {
          theCounter--;
          std::cout << '*';
     }
     std::cout << '\n';
     return 0;
} //end drawBar

Recommended Answers

All 2 Replies

First, please use code tags for your code.

Second, place

cin.get();

right before return 0 in your main. That will hold the console window open until the user presses enter. Also, why do you have your drawbar function returning an integer? It seems like it should be a void function...

-D

Also this is another way of stopping the program:

system("PAUSE");

If cin.get(); should fail in anyway use that as an alternative.

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.