Visual C++ 2010 errors

I am having trouble with this very simple program. I am using Visual C++ 2010, and i keep getting 2 errors on line 42 and 45 both of which say undeclared identifier. can someone look at my code and possibly see what im doing wrong. The errors are for the int height.
//INCLUDES
#include "stdafx.h"
#include <iostream>
using namespace std;

void print_pyramid(int height);

//MAIN FUNCTION
int _main()
{
int pyramidheight;

printf("This will build a pyramid on your sceen.\n");

printf("How high would you like this pyramid to be? ");
cin >> pyramidheight;

while(pyramidheight > 50 || pyramidheight <1)

{
printf("Please pick a number between 1 and 50");
cin >> pyramidheight;

}

print_pyramid(pyramidheight);

return 0;
}
//Pyramid Function
int print_pyramid()
{
int line;
int const MARGIN = 10;

printf("\n\n");

for(line = 1 ; line <= height ; line++)
{
int count;
int totalspaces = MARGIN + height - line;

for(count = 1 ; count <= totalspaces ; count++)
printf("' '");

for(count = 1 ; count <= line * 2 ; count++)
printf("*");

printf("\n");
}

printf("\n\n");

return 0;
}


Sorry its not that neat, but im working on it.
Last edited on
Variable height is not declared in the function.
Ok. Now i declared int height in the print_pyramid function and i had to change 2 lines in my code, now it only gives me 1 error at line 28 saying identifier not found. Heres my code now:


//INCLUDES
#include "stdafx.h"
#include <iostream>
using namespace std;

//MAIN FUNCTION
int _main()
{
int pyramidheight;

printf("This will build a pyramid on your sceen.\n");

printf("How high would you like this pyramid to be? ");
cin >> pyramidheight;

while(pyramidheight > 50 || pyramidheight <1)

{
printf("Please pick a number between 1 and 50");
cin >> pyramidheight;

}

print_pyramid(pyramidheight);

return 0;
}
//Pyramid Function
int print_pyramid(void)
{
int line;
int height;
int const MARGIN = 10;

printf("\n\n");

for(line = 1 ; line <= height ; line++)
{
int count;
int totalspaces = MARGIN + height - line;

for(count = 1 ; count <= totalspaces ; count++)
printf("' '");

for(count = 1 ; count <= line * 2 ; count++)
printf("*");

printf("\n");
}

printf("\n\n");

return 0;
}

it is in the main function the error is at print_pyramid(pyramidheight);
Last edited on
The compiler does not know what is print_pyramid when it meets the statement

print_pyramid(pyramidheight);

because this name was not declared yet.

Moreover you are calling the function passing an argument to it while later you are defining it without a pparameter

int print_pyramid(void)
Last edited on
Ok. If im right you meant i need to change it to int print_pyramid(void), i did that and its still giving me that same error. The error for print_pyramid(pyramidheight);



Sorry this is my 1st time using visual c++, when i took the 1 year in high school for vb and c++, we were usin visual basic and borland turbo c++.
If you want to pass arguments to a function you should declare it with parameters.
So as for your program, you should place a declaration of the function before its first reference and you should decide either your function shall have a parameter or shall not.
Last edited on
ok, i declared it, and now im still only getting one error at print_pyramid(pyramidheight), the error is function does not take 1 arguments. When i move my mouse over (pyramidheight) it says error: has to many arguments. so im thinking the (pyramidheight) is the error.


This is starting to drive me crazy, its simple, yet i feel dumb that i cannot seem to fix it, but i am asking question. I wont quit.
Always start with code tags ;)
Doesn't this look more pretty ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "stdafx.h"
#include <iostream>
using namespace std;

//MAIN FUNCTION
int _main()
{
int pyramidheight;

printf("This will build a pyramid on your sceen.\n");

printf("How high would you like this pyramid to be? ");
cin >> pyramidheight;

while(pyramidheight > 50 || pyramidheight <1)

{
printf("Please pick a number between 1 and 50");
cin >> pyramidheight;

}

print_pyramid(pyramidheight);

return 0;
}
//Pyramid Function
int print_pyramid(void)
{
int line;
int height;
int const MARGIN = 10;

printf("\n\n");

for(line = 1 ; line <= height ; line++)
{
int count;
int totalspaces = MARGIN + height - line;

for(count = 1 ; count <= totalspaces ; count++)
printf("' '");

for(count = 1 ; count <= line * 2 ; count++)
printf("*");

printf("\n");
}

printf("\n\n");

return 0;
}

vlad from moscow already said what the problem is.
I'll point u to the lines...What is wrong with lines 23 and 28 ?
Last edited on
Thank you guys for your help, i couldn't have fixed it without you.

Sometimes i can be a little slow on understanding something other times i can be fast. Yes it does look more pretty.
Topic archived. No new replies allowed.