return function working too soon?
Hi I have a small assignment that Im doing. It has a text menu and user enters numbers to call certain functions. All but one of the functions work correctly. The main method calls a couple of functions including the menu fuction which then calls the Pyramid function below. The output should look something like what is below if the user enters 'C'
A
ABA
ABCBA
I call it and it will show me the first prompt, then it will display the menu once again. It is weird because the function asks for a character, the menu calls for a integer, but i can use an integer or a character and it will work with its corresponding function.
Here is the code for the function:
Code:
void Pyramid()
{
char character;
char current;
char current_line;
int spaces = 0;
clrscr(); /*clears screen*/
printf("Please enter an uppercase character\n");
scanf("%c", &character);
character = toupper(character); /*converts to uppercase*/
for (current_line = 'A'; current_line <= character; current_line++) { /*to calculate total number of lines and when to stop printing*/
spaces = (character - current_line - 1); /*sets number of spaces for a particular line*/
for (spaces = spaces; spaces >= 0; spaces--) { /*displays spaces*/
printf(" ");
}
for (current = 'A'; current < current_line + 1; current++) { /*displays ascending characters*/
printf("%c",current);
}
current = current - 1; /*prevents repeating characters*/
for (current = current - 1; current >= 'A'; current--) { /*displays decending characters*/
printf("%c",current);
}
printf("\n"); /*starts next line*/
}
//return 0;
} /*end pyramid*/
One thing I did notice though if I ran it as a stand alone program everything worked fine. Im rather stumped actually. Does anyone know why it seems to be missing the 'for' statements and returning, (even though i have commented it out as a precaution). Thanx