I would like to write a program that takes a input from the user and calculates the triangular number. There should also be an option to ask the user if he wants to take another input or exit and that needs to be done using while or do...while. I have the following code written but doesn't do what is intended:
#include <stdio.h>
int main(void)
{
int n, number, triangularNumber;
char s = 'Y';
while (s == 'Y') {
printf("What triangular number do you want? ");
scanf("%i", &number);
triangularNumber = 0;
for (n = 1; n <= number; ++n)
triangularNumber += n;
printf("Triangular number %i is %i\n\n", number, triangularNumber);
printf("Do you want to continue?\n");
scanf("%c", &s);
}
return 0;
}
The above code only does it once after which it exits. How can I make it run the loop again based on the input I give? Thanks in advance.