User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,554 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,457 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 363 | Replies: 1
Reply
Join Date: Oct 2007
Location: dundee
Posts: 5
Reputation: sugarflaps is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sugarflaps sugarflaps is offline Offline
Newbie Poster

Help help please

  #1  
Oct 17th, 2007
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
Last edited by Narue : Oct 17th, 2007 at 11:40 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: help please

  #2  
Oct 17th, 2007
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 ;
}
I'm here to prove you wrong.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC