Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- xxxxxxxxxxxxxxxxxxxxxxxxxxx.cpp
- Book:
- Savitch_2018_Problem Soving with C++
- 2 C++ Basics
- p 136
- Date: xx June 2022
- Author: Eton Williams
- Required:
- xxxxxx
- xxxxxxx
- */
- #include <iostream>
- #include <cmath>
- using namespace std;
- //prototype functions
- double input_double();
- char input_char ();
- char repeat_query();
- void setDecimalPlaces();
- //initialize global variables and CONSTANTS
- char REPEAT; //User inputs this to determine a repeat of the program
- int main()
- {
- // initialize variables
- const double OUNCES_IN_TON = 35273.92;
- double xxxxxxxxxx ;
- int xx ;
- // Start and Program description
- cout << "\n\t\t\t\t\t\t\t= BEGIN PROGRAM =\n" << endl;
- cout << "This program will: \n\n"
- << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n"
- << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.\n"
- << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n\n";
- do{ //runs repeatedly
- // prompt for input
- cout << "\n\n\t\t\t\t\t\t\t\t= NEW INPUT =\n" << endl;
- cout << "\n xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx? ";
- xxxxxxxxxx = input_double();
- cout << "\n nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx? ";
- xxxxxxxxxx = input_double();
- // Echo input
- cout << "\n\n\t\tYou entered: \t xxxxxxxxxxxxxxxxx "
- << xxxxxxxxxx
- << " xxxxxxxxxx "
- << xxxxxxxxxx
- << " xxxxxxxxxxxxxxxxx.\n";
- // Calculation
- // function to query if user wishes to continue
- REPEAT = repeat_query();
- } while (REPEAT == 'y' || REPEAT == 'Y'); //condition to repeat the program
- //echo input
- cout << "\n\nYou entered: " << REPEAT << endl;
- // end program
- cout << "\n\n\t\t\t\t\t\t\t~ End of Program ~\n";
- cout << endl;
- return 0;
- }
- // function for taking numerical input ( double) from the user
- double input_double ()
- {
- double entered_number;
- std::cout << " (enter number): ";
- std::cin >> entered_number;
- return entered_number;
- }
- // function to format number of decimal places
- void setDecimalPlaces()
- {
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- cout.precision(8); // set number of decimal places in bracket
- }
- // function to query if user wishes to repeat program
- char repeat_query()
- {
- char ans;
- std::cout << "\nRepeat Program ? (enter y/n): ";
- std::cin >> ans;
- return ans;
- }
- // function to take y/ n char input
- char input_char ()
- {
- char entered_letter = 'a';
- do
- {
- std::cout << " (enter y/n): ";
- std::cin >> entered_letter;
- } while ( entered_letter != 'y' || entered_letter != 'Y' || entered_letter != 'n'|| entered_letter != 'N' );
- return entered_letter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement