| | |
Beginner C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 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
*
**
***
****
*****
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
0
#2 Nov 3rd, 2009
First, please use code tags for your code.
Second, place 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
Second, place
C++ Syntax (Toggle Plain Text)
cin.get();
-D
Last edited by dgr231; Nov 3rd, 2009 at 3:55 pm.
•
•
Join Date: Nov 2008
Posts: 29
Reputation:
Solved Threads: 0
0
#3 Nov 3rd, 2009
Also this is another way of stopping the program:
If cin.get(); should fail in anyway use that as an alternative.
C++ Syntax (Toggle Plain Text)
system("PAUSE");
![]() |
Similar Threads
- What program language should a beginner use? (IT Professionals' Lounge)
- C++ Beginner - #include recursion problem (C++)
- MS Access Beginner (MS SQL)
- PHP Beginner Here (PHP)
- beginner (C++)
- Beginner's questions: C++ and databases (C++)
- beginner needs help with game programming (Game Development)
Other Threads in the C++ Forum
- Previous Thread: Problems With Simple C++ Battle System; Need Help
- Next Thread: Give me the explanation for this output
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





