944,167 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 430
  • C++ RSS
Nov 3rd, 2009
0

Beginner C++

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jsmarts is offline Offline
1 posts
since Nov 2009
Nov 3rd, 2009
0
Re: Beginner C++
First, please use code tags for your code.

Second, place
C++ Syntax (Toggle Plain Text)
  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; Nov 3rd, 2009 at 3:55 pm.
Reputation Points: 55
Solved Threads: 7
Junior Poster in Training
dgr231 is offline Offline
76 posts
since Aug 2009
Nov 3rd, 2009
0
Re: Beginner C++
Also this is another way of stopping the program:
C++ Syntax (Toggle Plain Text)
  1. system("PAUSE");
If cin.get(); should fail in anyway use that as an alternative.
Reputation Points: 8
Solved Threads: 4
Junior Poster in Training
Shinedevil is offline Offline
71 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problems With Simple C++ Battle System; Need Help
Next Thread in C++ Forum Timeline: Give me the explanation for this output





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC