d_leet Posted September 2, 2005 Report Share Posted September 2, 2005 Ok I'm starting to learn C and I'm working with while statements. I'm trying to write a program that will let me enter an integer and then make a square out of asterisks with that integer I entered being the number of asterisks on a side.Like if I enter 5 I should get this:*************************Yea it's kind of a rectangle but lets call it a square lol.This is what I have but it only prints one line of asterisks#include <stdio.h> int main() { int side; int counter1 = 1; int counter2 = 1; printf("Enter an integer: "); scanf("%d", &side); while(counter1 <= side) { while(counter2 <= side) { printf("*"); counter2++; } counter1++; printf("\n"); } printf("Enter 1 to quit"); scanf("%d", &side); return 0; }Thanks in advance. Quote Link to post Share on other sites
jcl Posted September 2, 2005 Report Share Posted September 2, 2005 Consider the value of counter2 after the first time through the outer loop. Quote Link to post Share on other sites
d_leet Posted September 2, 2005 Author Report Share Posted September 2, 2005 Consider the value of counter2 after the first time through the outer loop.<{POST_SNAPBACK}>Ohhh I see it now, thank you very much I have it working now. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.