0

hi im new to c++ and i trying to create a triangle series which looks a bit like this
*
**
***
****
*****
*
**
*
*
**
***
****
*****

here is my code so far and my error message

//Lyndsey Scott
//Tutorial 4
//Simple c++ program using functions
//16th October 2007

#include <iostream> // using the main library
using namespace std;

// Function declarations
char get_char_wanted () ;
int get_num_rows (int num_rows) ;
int get_num_colms (int num_colms) ;
void draw_line (char wanted_char) ;

int main ()
{ // indicates begining of the program
	
	char wanted_char = get_char_wanted () ;

	
		num_rows = get_num_rows ;

	    num_colms = get_num_colms ;

	draw_line (wanted_char) ;
}

// Function definitions.
// Function to get character
char get_char_wanted ()
{
	char wanted_char ;
	{
		cout << "input character wanted" << endl ;
		cin >> wanted_char ;
		return wanted_char ;
	}

//Function to specify number of rows.
{
	int get_num_rows () ;
	{
		int num_rows ;
		cout << "enter number of rows" << endl ;
		cin >> num_rows ;
		return num_rows ;
	}

// Function to specify number of coloumns.
{
	int get_num_colms () ;
	{
		int num_colms ;
		cout << "please enter the number of coloumn" << endl ;
		cin >> num_colms ;
		return num_colms ;
	}

// Function to draw line of characters.
	{
	int rows ;
	for ( int i = 1 ; i <= rows ; i ++ )
	{
		cout << wanted_char ;
	}
	
	int colms ;
	for ( int j = 1 ; j <= colms ; j ++ )
	{
		cout << wanted_char ;
	}
	cout << endl  << endl ;
	}

error messages

c:\documents and settings\lyndsey scott\my documents\uni stuff\msc remote sensing\c++programs\tutorial4a\tutorial4a.cpp(21) : error C2065: 'num_rows' : undeclared identifier
1>c:\documents and settings\lyndsey scott\my documents\uni stuff\msc remote sensing\c++programs\tutorial4a\tutorial4a.cpp(23) : error C2065: 'num_colms' : undeclared identifier
1>c:\documents and settings\lyndsey scott\my documents\uni stuff\msc remote sensing\c++programs\tutorial4a\tutorial4a.cpp(80) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\lyndsey scott\my documents\uni stuff\msc remote sensing\c++programs\tutorial4a\tutorial4a.cpp(50)' was matched

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Narue
0

Wow. Scary. The first two errors you're getting come from the fact that you can't use a variable if you haven't declared it first. num_rows and num_colms don't exist in main. The next error is because your syntax is completely screwed up. None of the braces match, there are extra braces, and it you're even missing a function tag. Compare this to what you have:

//Lyndsey Scott
//Tutorial 4
//Simple c++ program using functions
//16th October 2007

#include <iostream> // using the main library
using namespace std;

// Function declarations
char get_char_wanted();
int get_num_rows();
int get_num_colms();
void draw_line(char wanted_char, int rows, int colms);

int main()
{
  char wanted_char = get_char_wanted();
  int num_rows = get_num_rows();
  int num_colms = get_num_colms();

  draw_line (wanted_char, num_rows, num_colms);
}

// Function definitions.
// Function to get character
char get_char_wanted()
{
  char wanted_char;
  cout << "input character wanted" << endl;
  cin >> wanted_char;
  return wanted_char;
}

//Function to specify number of rows.
int get_num_rows()
{
  int num_rows;
  cout << "enter number of rows" << endl;
  cin >> num_rows;
  return num_rows;
}

// Function to specify number of coloumns.
int get_num_colms()
{
  int num_colms;
  cout << "please enter the number of coloumn" << endl;
  cin >> num_colms;
  return num_colms;
}

// Function to draw line of characters.
void draw_line(char wanted_char, int rows, int colms)
{
  for ( int i = 1 ; i <= rows ; i ++ )
  {
    cout << wanted_char ;
  }

  for ( int j = 1 ; j <= colms ; j ++ )
  {
    cout << wanted_char ;
  }
  cout << endl  << endl ;
}
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.