Advertisement
etonw

Savitch TEMPLATE

May 30th, 2022 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. /*
  2. xxxxxxxxxxxxxxxxxxxxxxxxxxx.cpp
  3.  
  4. Book:
  5.     Savitch_2018_Problem Soving with C++
  6.     2 C++ Basics
  7.     p 136
  8.  
  9. Date:   xx June 2022
  10.  
  11. Author:    Eton Williams
  12.  
  13. Required:
  14. xxxxxx
  15. xxxxxxx
  16.  
  17. */
  18.  
  19. #include <iostream>
  20. #include <cmath>  
  21. using namespace std;
  22.  
  23. //prototype functions
  24. double input_double();
  25. char input_char ();
  26. char repeat_query();
  27. void setDecimalPlaces();
  28.  
  29. //initialize global variables and CONSTANTS
  30. char REPEAT;  //User inputs this to determine a repeat of the program
  31.  
  32. int main()
  33. {
  34.     // initialize variables
  35.     const double OUNCES_IN_TON = 35273.92;
  36.     double xxxxxxxxxx ;
  37.     int xx ;
  38.    
  39.  
  40.     // Start and Program description
  41.     cout << "\n\t\t\t\t\t\t\t= BEGIN PROGRAM =\n" << endl;
  42.     cout << "This program will: \n\n"
  43.          << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n"
  44.          << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.\n"
  45.          << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n\n";
  46.    
  47.     do{ //runs repeatedly
  48.         // prompt for input
  49.         cout << "\n\n\t\t\t\t\t\t\t\t= NEW INPUT =\n" << endl;
  50.         cout << "\n xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx? ";
  51.         xxxxxxxxxx = input_double();
  52.         cout << "\n nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx? ";
  53.         xxxxxxxxxx = input_double();
  54.        
  55.         // Echo input
  56.         cout << "\n\n\t\tYou entered: \t xxxxxxxxxxxxxxxxx "
  57.              << xxxxxxxxxx
  58.              << " xxxxxxxxxx "
  59.              << xxxxxxxxxx
  60.              << " xxxxxxxxxxxxxxxxx.\n";
  61.        
  62.          // Calculation
  63.        
  64.         // function to query if user wishes to continue
  65.         REPEAT = repeat_query();  
  66.     } while (REPEAT == 'y' || REPEAT == 'Y');    //condition to repeat the program
  67.  
  68.     //echo input
  69.     cout << "\n\nYou entered: " << REPEAT << endl;
  70.  
  71.     // end program
  72.     cout << "\n\n\t\t\t\t\t\t\t~ End of Program ~\n";
  73.     cout << endl;
  74.     return 0;
  75. }
  76.  
  77. // function for taking numerical input ( double) from the user
  78. double input_double ()
  79. {
  80.     double entered_number;
  81.     std::cout << " (enter number): ";
  82.     std::cin >> entered_number;
  83.     return entered_number;
  84. }
  85.  
  86. // function to format number of decimal places
  87. void setDecimalPlaces()
  88. {
  89.     cout.setf(ios::fixed);     
  90.     cout.setf(ios::showpoint);
  91.     cout.precision(8);          // set number of decimal places in bracket
  92. }
  93.  
  94. // function to query if user wishes to repeat program
  95. char repeat_query()
  96. {
  97.    char ans;
  98.    std::cout << "\nRepeat Program ? (enter y/n): ";
  99.    std::cin >> ans;
  100.    return ans;
  101. }
  102.  
  103. // function to take y/ n char input
  104. char input_char ()
  105. {
  106.     char entered_letter = 'a';
  107.     do
  108.         {
  109.             std::cout << " (enter y/n): ";
  110.             std::cin >> entered_letter;
  111.        
  112.         } while ( entered_letter != 'y' || entered_letter != 'Y' || entered_letter != 'n'|| entered_letter != 'N'  );
  113.     return entered_letter;
  114. }
  115.  
  116.  
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement