Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. //Include the header file for
  2.  
  3. //visual studio.
  4.  
  5. #include "stdafx.h"
  6.  
  7. //Include the header file.
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. //Define the main() function.
  14.  
  15. int main()
  16.  
  17. {
  18.  
  19. //Declare the variables.
  20.  
  21. int i;
  22.  
  23. int lower_value, upper_value;
  24.  
  25. bool loop_value = true;
  26.  
  27. //Begin the for loop.
  28.  
  29. while (loop_value)
  30.  
  31. {
  32.  
  33. //Prompt the user to enter the
  34.  
  35. //lower_value and upper_value.
  36.  
  37. cout << "Enter lower and upper values: " << endl;
  38.  
  39. cin >> lower_value >> upper_value;
  40.  
  41. //Check the input value to be valid.
  42.  
  43. if ((lower_value<32 || lower_value>126))
  44.  
  45. {
  46.  
  47. //Display the statement.
  48.  
  49. cout << "Values must be in range 32"
  50.  
  51. << " to 126 inclusive \n";
  52.  
  53. }//End of if condition.
  54.  
  55. //Else if part.
  56.  
  57. else if ((lower_value > upper_value))
  58.  
  59. {
  60.  
  61. //Display the statement.
  62.  
  63. cout << "Lower value can't be greater"
  64.  
  65. << "than Upper \n";
  66.  
  67. }//End of else if condition.
  68.  
  69. //Else part.
  70.  
  71. else
  72.  
  73. {
  74.  
  75. //Update the loop_value to false.
  76.  
  77. loop_value = false;
  78.  
  79. }//End of else part.
  80.  
  81. }//End of while loop.
  82.  
  83. //Display the values with the statement.
  84.  
  85. cout << "Characters for ASCII values between "
  86.  
  87. << lower_value << " and " << upper_value;
  88.  
  89. //Display the line.
  90.  
  91. cout << "\n----+----+----+-\n";
  92.  
  93. //Begin the for loop.
  94.  
  95. for (i = lower_value; i <= upper_value; i++)
  96.  
  97. {
  98.  
  99. //Display the ASCII values.
  100.  
  101. cout << (char)i;
  102.  
  103. //Go to the new line after every 16
  104.  
  105. //values.
  106.  
  107. if ((i - lower_value + 1) % 16 == 0)
  108.  
  109. {
  110.  
  111. //Print the next line.
  112.  
  113. cout << "\n";
  114.  
  115. }//End of if condition.
  116.  
  117. }//End of for loop.
  118.  
  119. //Display the line.
  120.  
  121. cout << "\n----+----+----+-\n";
  122.  
  123. //Include the command to pause
  124.  
  125. //the screen in visual studio.
  126.  
  127. system("pause");
  128.  
  129. //Return the value to the main() function.
  130.  
  131. return 0;
  132.  
  133. }//End of the main() function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement