Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef enum {
- false,
- true
- }bool; // this is a boolean declaration.
- bool ask_question(void);
- int main(void) {
- int input;
- bool answer;
- while(true) {
- printf("input : ");
- scanf("%d", &input);
- for(int i = 1; i <= input; i++) {
- for(int j = 1; j <= i; j++){
- printf("*");
- }
- printf("\n");
- }
- answer = ask_question();
- if(answer == false)
- break;
- else
- continue;
- }
- return 0;
- }
- bool ask_question(void) {
- /**
- * note that this function just make sure that the user enteredonly '1' or '0' and nothing else that that.
- * you can modify this this function to get a 'yes' or 'no' answer or (y/n) answer.
- */
- int temp;
- while(true) {
- printf("would you like to continue ? (1/0) ");
- scanf("%d", &temp);
- if(temp == 1) {
- return true;
- }
- else if(temp == 0) {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement