Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4.  
  5. int get_positive_int(string prompt);
  6. void get_spaces(int num);
  7. void get_hashes(int num);
  8.  
  9. int main(void)
  10. {
  11. int height = get_positive_int("Height: ");
  12. int spaces = height - 1;
  13. printf("%i\n", height);
  14. int hashes = 2;
  15.  
  16. for (int i = 0; i < height; i++)
  17. {
  18. get_spaces(spaces);
  19. get_hashes(hashes);
  20. printf("\n");
  21. spaces--;
  22. hashes++;
  23. }
  24.  
  25. }
  26.  
  27.  
  28.  
  29. // Check the conditions for a valid prompt
  30. // 0. Check if prompt is not less or equal than 0
  31. // 1. Check if prompt is not bigger than 8
  32. // 2. Check if there are no letters or words
  33. // 3. check if input is null
  34.  
  35. int get_positive_int(string prompt)
  36. {
  37. int n;
  38. do
  39. {
  40. n = get_int("%s", prompt);
  41. }
  42. while (n <= 0 || n > 8 || n != '\0' || !isdigit(n));
  43. return n;
  44. }
  45.  
  46. void get_spaces(int num)
  47. {
  48. for(int i = 0; i < num; i++)
  49. {
  50. printf(" ");
  51. }
  52. }
  53.  
  54. void get_hashes(int num)
  55. {
  56. for(int i = 0; i < num; i++)
  57. {
  58. printf("#");
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement