Advertisement
M4ritimeSeeker

PASS Week 10/06

Oct 5th, 2020 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.36 KB | None | 0 0
  1. PROBLEM #1
  2.  
  3. Create a program using the skeleton below that will prompt the user to enter in two integer
  4. values: nbr1 and nbr2. Use an if/else construct to print out nbr1 <= nbr2 or nbr1 > nbr2.
  5.  
  6. /*** SKELETON CODE ***/
  7.  
  8. #include <stdio.h>
  9.  
  10. int main (void)
  11. {
  12.  
  13.     // Local Declarations
  14.     int nbr1;
  15.     int nbr2;
  16.  
  17.     // Statements
  18.     printf("Please enter two integers: ");
  19.     scanf ("%d %d", &nbr1, &nbr2);
  20.  
  21.     //Your code here
  22.  
  23.     return 0;
  24. } // End main
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. PROBLEM #2
  33.  
  34. Modify the program from Problem #1 to use nested if/else blocks of code to determine if in
  35. the case where nbr1 <= nbr2, further determine which case is true nbr1 < nbr2, nbr1 ==
  36. nbr2
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. PROBLEM #4 (I pushed Problem #3 to the end)
  53.  
  54. In this problem, we will be calculating a students letter grade by using the percentage.
  55. Treat the percentage as an integer between 0-100.
  56. Using the skeleton code below complete a switch statement in the
  57. function that takes the score value and returns the char value that
  58. corresponds to the letter grade earned. 90 to 100 is an ‘A’, 80 to 89
  59. is a ‘B’ etc. HINT: You can narrow the number of cases by changing the
  60. value from a 93 to a 9 or a 26 to a 2 by using integer division. What
  61. if the user supplies a floating point? Implicit or explicit casting can
  62. be used.
  63.  
  64. /*** SKELETON CODE ***/
  65.  
  66. #include <stdio.h>
  67.  
  68. // Function Declarations
  69. char scoreToGrade (float score);
  70.  
  71. int main (void)
  72. {
  73.     // Local Declarations
  74.     float score;
  75.     char grade;
  76.  
  77.     // Local Statements
  78.     printf("Enter the test score (0-100): ");
  79.     scanf ("%f", &score);
  80.  
  81.     grade = scoreToGrade (score);
  82.  
  83.     printf("The grade is: %c\n", grade);
  84.  
  85.     return 0;
  86. } // end main
  87.  
  88.  
  89. /* ==================== scoreToGrade ===================
  90. This function calculates the letter grade for a score.
  91.  Pre the parameter score
  92.  Post returns the grade
  93. */
  94. char scoreToGrade (float score)
  95. {
  96.     // Local Declarations
  97.     char grade;
  98.     int temp;
  99.  
  100.     // Statements
  101.     temp = (int)(score / 10); //Without the cast it would still be narrowed to an integer
  102.  
  103.     //YOUR SWITCH STATEMENT HERE
  104.  
  105.     return grade;
  106. }//end function ScoreToGrade
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. PROBLEM #5
  123.  
  124. Using the random number generator compose a program that seeds the
  125. random number generator using system time. Use the random number
  126. function to returns a value within a range of 1 - 3. Use a switch
  127. statement to determine the following. If the number returned is 1 print
  128. out “The computer chose Rock.”, if it’s 2 print out “The computer chose
  129. Paper.”, if it’s 3 print out “The computer chose Scissors.”
  130.  
  131. Set the range: range = (max value - min value) + 1;
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. (BONUS) PROBLEM #3
  145.  
  146. Using nested if/else conditions, write a program that will prompt for then take three integer
  147. values as input. Your if/else construct should determine which value is the median value of
  148. the three. If you use a comparison operator ‘==’ make sure not to confuse it with the ‘=
  149. assignment operator. It might make it easier to draw the various conditions using pencil and
  150. paper. This is a simple example of where a flowchart design tool could help verify your logic.
  151.  
  152. /*** SKELETON CODE ***/
  153.  
  154. #include <stdio.h>
  155.  
  156. int main(void)
  157. {
  158.     int a, b, c, median;
  159.  
  160.     printf("Enter in 3 integer values.\n");
  161.     scanf("%d", &a);
  162.     scanf("%d", &b);
  163.     scanf("%d", &c);
  164.  
  165.     //YOUR CODE HERE
  166.  
  167.     return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement