Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Ch6AppE03.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//Ch6AppE03.cpp
//Displays a shipping charge based on a state code
//Created/revised by <your name> on <current date>

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
int code;
cout << "Please enter a state code: ";
cin >> code;
switch(code)
{
case 1:
cout << "25";
break;
case 2:
cout << "30";
break;
case 3:
cout << "40";
break;
case 4:
cout << "40";
break;
case 5:
cout << "30";
break;
case 6:
cout << "30";
break;
default:
cout << "Incorrect state code";
break;
}
cout << endl;
return 0;
} //end of main function
63 changes: 63 additions & 0 deletions Ch6AppE06.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//Ch6AppE06.cpp
//Displays the number of daily calories
//needed to maintain your current weight
//Created/revised by <your name> on <current date>

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
int weight;
char gender;
char activity;
int cal;

cout << "What gender are you? (M - male, F - Female) ";
cin >> gender;

cout << "How active are you? (I - inactive, A - active) ";
cin >> activity;

cout << "How much do you weigh? ";
cin >> weight;

switch(gender)
{
case 'M':
switch(activity)
{
case 'I':
cal = weight * 13;
break;
case 'A':
cal = weight * 15;
break;
default:
cout << "Invalid response" << endl;
}
break;

case 'F':
switch(activity)
{
case 'I':
cal = weight * 10;
break;
case 'A':
cal = weight * 12;
break;
default:
cout << "Invalid response" << endl;
}
break;

default:
break;
}
cout << "You need " << cal << " Calories" << endl;
return 0;
} //end of main function
53 changes: 53 additions & 0 deletions Ch6AppE08.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//Ch6AppE08.cpp
//Displays the answer to arithmetic problems
//Created/revised by <your name> on <current date>

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
char letter;
int num1;
int num2;
int ans;

cout << "What type of math would you like: " << endl;
cout << "(A - add, S - subtract, M - Multiply, D - Divisoin) ";
cin >> letter;

if(letter == 'A' || letter == 'S' || letter == 'M' || letter == 'D')
{
cout << "What numbers would you like to use:" << endl;
cout << "num 1: ";
cin >> num1;
cout << "num 2: ";
cin >> num2;
}
switch (letter)
{
case 'A':
ans = num1 + num2;
cout << ans << endl;
break;
case 'S':
ans = num1 - num2;
cout << ans << endl;
break;
case 'M':
ans = num1 * num2;
cout << ans << endl;
break;
case 'D':
ans = num1 / num2;
cout << ans << endl;
break;
default:
cout << "Please leave. We do not take kindly to rebels." << endl;
break;
}
return 0;
} //end of main function