Hi, can anybody help me with this program? I have to make a Christmas tree. Below is my current program but I think there may be a few errors and I don't know where to progress from here. Any help would be great!
C++ Code so far:
#include <iostream> //for cin >> and cout <<
#include <cassert> //for assert
#include <iomanip> //for endl
using namespace std;
//declare constants: symbols used for the drawing
const char BLANK( ' ');
const char LEAF( '#');
const char WOOD( '|');
const char EOL( '\n'); //end of line symbol
//declare variables
int treeHeight; //height of the tree
int branchLine; //loop counter for each line of the foliage
int main() //draw Xmas tree
{
cout << "\n\n\nName– 07/12/2013" << EOL << EOL; //TO BE MODIFIED
getValidHeight();
cout << EOL;
drawBranches();
drawTrunk();
cout << EOL;
system( "PAUSE"); //hold the screen until a key is pressed
return( 0);
}
//TO BE MODIFIED
void getValidHeight() //get valid height for the tree
{
//assert( TO BE COMPLETED );
cout << "\nSTUB: Enter an even number between 4 - 20 to determine the size of the tree";
cin >> treeHeight;
assert (treeHeight >= 3); cout << "Error, height is less than 4 ";
assert (treeHeight <= 21); cout << "Error, height is more than 20 ";
}
//TO BE MODIFIED
void drawBranches() //draw foliage
{
//assert( TO BE COMPLETED );
void drawABranch();
for ( branchLine = 1; branchLine <= (treeHeight - 2); ++branchLine)
drawABranch(); //draw one line of foliage
}
//TO BE MODIFIED
void drawABranch() //draw one line of foliage
{
//assert( TO BE COMPLETED );
//draw the spaces
cout << BLANK; //print a space
//draw the leaves
cout << LEAF << LEAF << LEAF; //print a leaf symbol
cout << EOL; //go to next line
}
//TO BE MODIFIED
void drawTrunk() //draw trunk
{
//assert( TO BE COMPLETED );
}
In void drawBranches(), the first command is void drawABranch();. This is a definition. If you just want to run it, use drawABranch();, without void.
You need to declare all your functions before main. Add
before the main function.
Some stylistic comment. It is a very bad habit to have global variables (those defined outside any function). Think about passing those parameters as arguments to functions, or return values.
One more note: please use code tags (the button with <> next to the edit box). It makes the code more readable.
Hi does any body know how to show ten float point numbers using <stdio.h> and using arrays
here is my code so far please tell me what i doing wrong becuase this code does not work
#include <stdio.h>
int main()
{
int i;
int num1;
int size;
int *myArray;
printf("How many numbers \n");
scanf_s("%d",&size);
@D14 numSpace? you mean namespace? usingnamespace std; is not a declaration of variables. It just says that all your commands that you are using are in the standard library. If you omit that line, you need to replace cin with std::cin, and same for cout. I think the same is true for assert
@theKarateKid why don't you post as a separate message?