Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. /**
  2. * @file p2.cpp
  3. *
  4. * CS 150 PE02: INTERMEDIATE SELECTION/LOGIC
  5. *
  6. * You have been dealt two cards, a and b.
  7. * Each card has a value 0-100. Set the variable
  8. * nearest to whichever value is nearest to 21
  9. * without going over.
  10. * Do not use any library functions.
  11. */
  12. int nearest(int a, int b)
  13. {
  14. int result;
  15.  
  16. // Your code goes here
  17. if (a + b <= 21)
  18. {
  19. int result = b;
  20. return result;
  21. }
  22. else if (a == 21)
  23. {
  24. int result = a;
  25. return result;
  26. }
  27. else if (b == 21)
  28. {
  29. int result = b;
  30. return result;
  31. }
  32. else if (a < b)
  33. {
  34. int result = a;
  35. return result;
  36. }
  37. else
  38. {
  39. return 0;
  40. }
  41. return result;
  42. }
  43.  
  44. ////////////////// STUDENT TESTS ///////////////////////
  45. #include <iostream>
  46. using namespace std;
  47. void studentTests()
  48. {
  49. cout << "Add your own code here" << endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement