Hi, I'm stuck on an assignment. I'm new to C and finding it quite intimidating and really stuck at present. I need the programme to continue running until a positive integer between 0 and including 8 has been input by the user, if another integer is entered ie -2 or 9 for example then the programme needs to prompt the user to enter Height again. Currently what the programme does when -2 is entered is return Height which is correct, but when 9 is entered, the programme ends, which is not what I want to happen.
If anyone can point me in the right direction I would be grateful. Current code is:
Code:
#include <cs50.h>
#include <stdio.h>
int get_positive_int(string prompt);
int main(void)
{
int Height = get_positive_int("Height: ");
for (int i = 0; i < Height && Height < 9; i++)
{
for (int j = Height - i - 1; j > 0; j--)
{
printf(" ");
}
for (int j = 0; j < i + 1; j++)
{
printf("#");
}
{
printf("\n");
}
}
}
//prompt user to input positive integer
int get_positive_int(string prompt)
{
int n;
do
{
n = get_int("%s", prompt);
}
while (n < 1);
return n;
}
// if less than 1 or greater than 8 then repeat previous step