For my HW assignment, I need to create a program that draws an asterisk-based triangle, which depends on user input. I got my program to work until the user enters an integer that displays the correct triangle, but my problem is when an invalid value is entered, how can I make it so that the user re-tries to represent the value? I looked at the forums and I was not able to find a similar question.
#include <stdio.h>
int main() {
int lines, a, b;
printf("Input a value from 1 to 15: ");
scanf("%d", &lines);
if(lines >= 1 && lines <= 15) {
for(a = 1; a <= lines; a++) {
for(b=1; b<= a; b++) {
printf("*");
}
printf("\n");
}
}
else {
printf("not valid");
}
system("pause");
}
source
share