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 if nbr1 <= nbr2 or else if nbr1 > nbr2.
- In your if/else statements, print out the statements verbatim like this:
- printf("nbr1 <= nbr2\n");
- /*** 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 in
- the case if nbr1 <= nbr2, the case is also true if nbr1 < nbr2 or else nbr1 == nbr2
- PROBLEM #3
- 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. Most of the code is given to you. You just have to
- write the switch statement itself.
- 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?
- /*** 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 #4
- 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;
- /*** SKELETON CODE ***/
- #include<stdio.h>
- #include<time.h>
- #define MAX 3
- #define MIN 1
- int main(void)
- {
- int range = ;
- int compChoice = ;
- switch(compChoice)
- {
- }
- printf("Good bye!\n");
- return 0;
- }//end main
- BONUS PROBLEM
- 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