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;
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;
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.
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.
#include "stdafx.h"
#include <iostream>
usingnamespace 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;
intconst 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 ?