I am trying to make a pyramid of hashtags somehow which I haven´t figured out yet, and trying my way step by step. (I´m doing the Cs50 course) When I came this far the program is working wohoo so far so good - BUT made an infinite loop. Why? Can you not have both for and while after eachother?
#include <stdio.h>
//Get positive integer from user
int get_pyramidrows_int(void);
int main(void)
{
int rows, i, j;
string hashtag = "#";
//Get positive integer up to 8
do
{
rows = get_pyramidrows_int();
}
while ( rows > 8);
//Print hashtags as many as rows
for (i =0; i < rows; i++)
j = 0;
while(j < rows)
{
printf("#");
(i++);
}
}
//Getting positive integer from user
int get_pyramidrows_int(void)
{
int n;
do
{
n = get_int("Write a number 1-8: ");
}
while( n < 1 );
return n;
}
so now I tried this instead
#include <cs50.h>
int main(void)
{
//Get prompt from user for rows
int rows, height, width, i;
do
{
rows = get_int("How many rows? ");
}
while(rows < 1 || rows > 8);
//Print rows of pyramid
for(height = 0; height < rows; height++)
{
for(width = rows; width > height; width--)
{
printf("#");
}
printf("#\n");
}
}