Hello Everyone!
I have an assignment for school that is really got the best of me.
Here is the question:
(2) Write a C program using while loop(s) in combination with only the following three output statements (Each one appearing ONLY ONCE in your program): printf("* "); printf("\n"); printf(“^“); to print the pattern:
* * * * * * * * ^ * * * * * * * * * * * * * * * * ^ * * * * * * * * * * * * * * * * ^ * * * * * * * *
Note: there is a space between each * and the first, third, and fifth lines have a space before the ^.
And here is my code:
#include<stdio.h>
int main () {
int star = 0;
int row = 1;
int hat = 1;
while(row < 6) {
printf(" *");
star++;
while(star > 8) {
while( (hat % 2) == 1) {
printf(" ^");
}
printf("\n");
row++;
}
}
return 0;
}
I've tried many different versions of this code, and most of them ended up with infinitely printing rows of *.
If anyone could help it would be great as I've tried and tried at this for a while now and even though I wish I could keep trying deadlines are deadlines and they always seem to come too fast.
Thanks
EDIT:
Rev.2 of the code:
include<stdio.h>
int main () {
int star = 0;
int row = 1;
int hat = 0;
while(row <= 6) {
printf(" *");
star++;
while(star >= 8) {
hat++;
if( (hat % 2) == 1) {
printf(" ^");
hat++;
}
printf("\n");
row++;
star = 0;
}
}
return 0;
}
Hopefully I am terminating the loops correctly but It seems not to be working. I'm not asking for a "get out of jail free" card but any are welcomed hah.