From e6854489bc7561051218f3d584c33b01a12a2dae Mon Sep 17 00:00:00 2001 From: mgilmore208528 Date: Wed, 17 Dec 2014 05:02:18 -0600 Subject: [PATCH] chapter 6 --- Ch6AppE03.cpp | 41 +++++++++++++++++++++++++++ Ch6AppE06.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++ Ch6AppE08.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 Ch6AppE03.cpp create mode 100644 Ch6AppE06.cpp create mode 100644 Ch6AppE08.cpp diff --git a/Ch6AppE03.cpp b/Ch6AppE03.cpp new file mode 100644 index 0000000..0ffbe17 --- /dev/null +++ b/Ch6AppE03.cpp @@ -0,0 +1,41 @@ +//Ch6ConE03.cpp +//Displays a message based on the number +//entered by the user +//Created/revised by on + +#include +using namespace std; + +int main() +{ + + int state = 0; + int charge = 0; + cout << "What state code are you shipping to?"; + cin >> state; + switch (state) + { + case 1: + charge = 25; + break; + case 2: + charge = 30; + break; + case 3: + charge = 40; + break; + case 4: + charge = 40; + break; + case 5: + charge = 30; + break; + case 6: + charge = 30; + break; + default: + cout << endl << "Incorrect state code" << endl; + } + cout << charge << endl; + return 0; +} diff --git a/Ch6AppE06.cpp b/Ch6AppE06.cpp new file mode 100644 index 0000000..a89057b --- /dev/null +++ b/Ch6AppE06.cpp @@ -0,0 +1,66 @@ +//Ch6ConE06.cpp +//Displays a message based on the number +//entered by the user +//Created/revised by on + +#include +using namespace std; + +int main() +{ + + char gender = ' '; + char active = ' '; + double cal = 0; + double weight = 0; + + cout << endl << "how much do you weigh? "; + cin >> weight; + + cout << endl << "A - Moderately active" << endl << "I - inactive" << endl; + cin >> active; + + cout << endl << "M - Male" << endl << "F - Female" << endl; + cin >> gender; + + gender = toupper(gender); + active = toupper(active); + + switch (gender) + { + case 'M': + switch (active) + { + case 'A': + cal = weight * 12; + break; + case 'I': + cal = weight * 10; + break; + + default: + cout << endl << "Incorrect input" << endl; + } + break; + + case 'F': + switch (active) + { + case 'A': + cal = weight * 15; + break; + case 'I': + cal = weight * 13; + break; + + default: + cout << endl << "Incorrect input" << endl; + } + break; + + default: + cout << endl << "Incorrect input" << endl; + } + cout << endl << cal << endl; + return 0; +} diff --git a/Ch6AppE08.cpp b/Ch6AppE08.cpp new file mode 100644 index 0000000..0d9a5d1 --- /dev/null +++ b/Ch6AppE08.cpp @@ -0,0 +1,77 @@ +//Ch6AppE08.cpp +//Displays the answer to arithmetic problems +//Created/revised by on + +#include +using namespace std; + +int main() +{ + double num1 = 0; + double num2 = 0; + double solution = 0; + char choice = ' '; + + cout << endl << "A - Addition" << endl << "S - Subtraction" << endl << "M - multiplication" << endl << "D - Division" << endl; + cout << "Which one would you like to do?" << endl; + cin >> choice; + choice = toupper(choice); + switch (choice) + { + case 'A': + cout << "Please enter a number" << endl; + cin >> num1; + cout << "Please enter another number" << endl; + cin >> num2; + solution = num1 + num2; + cout << "Your solution is " << solution << endl; + break; + + case 'S': + cout << "Please enter a number" << endl; + cin >> num1; + cout << "Please enter another number" << endl; + cin >> num2; + if (num1 >= num2) + { + solution = num1 - num2; + } + else + { + solution = num2 - num1; + } + cout << "Your solution is " << solution << endl; + break; + + case 'M': + cout << "Please enter a number" << endl; + cin >> num1; + cout << "Please enter another number" << endl; + cin >> num2; + solution = num1 * num2; + cout << "Your solution is " << solution << endl; + break; + + case 'D': + cout << "Please enter a number" << endl; + cin >> num1; + cout << "Please enter another number" << endl; + cin >> num2; + if (num1 >= num2) + { + solution = num1 / num2; + } + else + { + solution = num2 / num1; + } + cout << "Your solution is " << solution << endl; + break; + + default: + cout << endl << "Incorrect input" << endl; + } + + + return 0; +} \ No newline at end of file