Beginner C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 1
Reputation: jsmarts is an unknown quantity at this point 
Solved Threads: 0
jsmarts jsmarts is offline Offline
Newbie Poster

Beginner C++

 
0
  #1
25 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 73
Reputation: dgr231 is on a distinguished road 
Solved Threads: 7
dgr231's Avatar
dgr231 dgr231 is offline Offline
Junior Poster in Training
 
0
  #2
25 Days Ago
First, please use code tags for your code.

Second, place
  1. 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
Last edited by dgr231; 25 Days Ago at 3:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: Shinedevil is an unknown quantity at this point 
Solved Threads: 0
Shinedevil Shinedevil is offline Offline
Light Poster
 
0
  #3
25 Days Ago
Also this is another way of stopping the program:
  1. system("PAUSE");
If cin.get(); should fail in anyway use that as an alternative.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC