•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Location: dundee
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 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
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
*
**
***
****
*****
*
**
*
*
**
***
****
*****
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 ;
}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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C++ Forum
- Previous Thread: are double speed and double speed[1] the same?
- Next Thread: User defined functions



Linear Mode