Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROBLEM #1
- Create a program using the skeleton below that will prompt the user to enter in two integer
- values: nbr1 and nbr2. Use an if/else construct to print out nbr1 <= nbr2 or nbr1 > nbr2.
- /*** SKELETON CODE ***/
- #include <stdio.h>
- int main (void)
- {
- // Local Declarations
- int nbr1;
- int nbr2;
- // Statements
- printf("Please enter two integers: ");
- scanf ("%d %d", &nbr1, &nbr2);
- //Your code here
- return 0;
- } // End main
- PROBLEM #2
- Modify the program from Problem #1 to use nested if/else blocks of code to determine if in
- the case where nbr1 <= nbr2, further determine which case is true nbr1 < nbr2, nbr1 ==
- nbr2
- PROBLEM #4 (I pushed Problem #3 to the end)
- In this problem, we will be calculating a students letter grade by using the percentage.
- Treat the percentage as an integer between 0-100.
- Using the skeleton code below complete a switch statement in the
- function that takes the score value and returns the char value that
- corresponds to the letter grade earned. 90 to 100 is an ‘A’, 80 to 89
- is a ‘B’ etc. HINT: You can narrow the number of cases by changing the
- value from a 93 to a 9 or a 26 to a 2 by using integer division. What
- if the user supplies a floating point? Implicit or explicit casting can
- be used.
- /*** SKELETON CODE ***/
- #include <stdio.h>
- // Function Declarations
- char scoreToGrade (float score);
- int main (void)
- {
- // Local Declarations
- float score;
- char grade;
- // Local Statements
- printf("Enter the test score (0-100): ");
- scanf ("%f", &score);
- grade = scoreToGrade (score);
- printf("The grade is: %c\n", grade);
- return 0;
- } // end main
- /* ==================== scoreToGrade ===================
- This function calculates the letter grade for a score.
- Pre the parameter score
- Post returns the grade
- */
- char scoreToGrade (float score)
- {
- // Local Declarations
- char grade;
- int temp;
- // Statements
- temp = (int)(score / 10); //Without the cast it would still be narrowed to an integer
- //YOUR SWITCH STATEMENT HERE
- return grade;
- }//end function ScoreToGrade
- PROBLEM #5
- Using the random number generator compose a program that seeds the
- random number generator using system time. Use the random number
- function to returns a value within a range of 1 - 3. Use a switch
- statement to determine the following. If the number returned is 1 print
- out “The computer chose Rock.”, if it’s 2 print out “The computer chose
- Paper.”, if it’s 3 print out “The computer chose Scissors.”
- Set the range: range = (max value - min value) + 1;
- (BONUS) PROBLEM #3
- Using nested if/else conditions, write a program that will prompt for then take three integer
- values as input. Your if/else construct should determine which value is the median value of
- the three. If you use a comparison operator ‘==’ make sure not to confuse it with the ‘=’
- assignment operator. It might make it easier to draw the various conditions using pencil and
- paper. This is a simple example of where a flowchart design tool could help verify your logic.
- /*** SKELETON CODE ***/
- #include <stdio.h>
- int main(void)
- {
- int a, b, c, median;
- printf("Enter in 3 integer values.\n");
- scanf("%d", &a);
- scanf("%d", &b);
- scanf("%d", &c);
- //YOUR CODE HERE
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement