Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file p2.cpp
- *
- * CS 150 PE02: INTERMEDIATE SELECTION/LOGIC
- *
- * You have been dealt two cards, a and b.
- * Each card has a value 0-100. Set the variable
- * nearest to whichever value is nearest to 21
- * without going over.
- * Do not use any library functions.
- */
- int nearest(int a, int b)
- {
- int result;
- // Your code goes here
- if (a + b <= 21)
- {
- int result = b;
- return result;
- }
- else if (a == 21)
- {
- int result = a;
- return result;
- }
- else if (b == 21)
- {
- int result = b;
- return result;
- }
- else if (a < b)
- {
- int result = a;
- return result;
- }
- else
- {
- return 0;
- }
- return result;
- }
- ////////////////// STUDENT TESTS ///////////////////////
- #include <iostream>
- using namespace std;
- void studentTests()
- {
- cout << "Add your own code here" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement