Advertisement
yanni_yagami

Untitled

Apr 29th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. typedef enum {
  3.     false,
  4.     true
  5. }bool; // this is a boolean declaration.
  6.  
  7. bool ask_question(void);
  8.  
  9. int main(void) {
  10.     int input;
  11.     bool answer;
  12.  
  13.     while(true) {
  14.         printf("input : ");
  15.         scanf("%d", &input);
  16.  
  17.         for(int i = 1; i <= input; i++) {
  18.             for(int j = 1; j <= i; j++){
  19.                 printf("*");
  20.             }
  21.             printf("\n");
  22.         }
  23.  
  24.         answer = ask_question();
  25.  
  26.         if(answer == false)
  27.             break;
  28.  
  29.         else
  30.             continue;
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
  36. bool ask_question(void) {
  37.     /**
  38.      * note that this function just make sure that the user enteredonly  '1' or '0' and nothing else that that.
  39.      * you can modify this this function to get a 'yes' or 'no' answer or (y/n) answer.
  40.      */
  41.     int temp;
  42.     while(true) {
  43.         printf("would you like to continue ? (1/0) ");
  44.         scanf("%d", &temp);
  45.        
  46.         if(temp == 1) {
  47.             return true;
  48.         }
  49.  
  50.         else if(temp == 0) {
  51.             return false;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement