1

Can someone help me with problem set 1? I got the pyramid working, but my height restrictions seems to not work.

When I type in letters and negative numbers for height, the program does not print out the diagram and keeps asking the user for another number. However, when I type a number that's greater than 23, it prints the pyramid out when it shouldn't print anything out, but instead ask the user for another number between 0 and 23.

Below is a snippet of my code. Is there a mistake?

int main(void)
{

    int height; 

    do
    {
        printf("height: ");
        height = GetInt();

       ....

    } while(height>=0||height<=23);

}
3

The while condition in a do while loop is the condition that causes the loop to repeat.

do
{
    //this
}
while (this is true)

Can you see why yours is incorrect? You have used the opposite condition.

| improve this answer | |
  • 1
    oh ok, Thank you! I corrected my program and it works now. – Xihai Luo Jan 6 '15 at 22:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .