0

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

Edited by Reverend Jim: Fixed formatting

3
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by Shinedevil
0

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

Edited by dgr231: n/a

0

Also this is another way of stopping the program:

system("PAUSE");

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.