Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROBLEM #1: If-Else Statements
- Create a program that will prompt the user to enter in two integer
- values; Store them in the variables nbr1 and nbr2 (These steps have been done for you).
- Use an if/else construct to print out the following conditions if they
- are true “nbr1 <= nbr2” or “nbr1 > nbr2”.
- SAMPLE OUTPUT:
- Please enter two integers: 4 5
- 4 <= 5
- MORE SAMPLE OUTPUT:
- Please enter two integers: 7 7
- 7 <= 7
- /****** 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: Nesting If-Else Statements
- In this problem, you will go deeper with your If-Else statements by nesting (inserting) ANOTHER If-Else
- statement inside of an already existing one.
- Modify the program from PROBLEM #1. INSIDE the block that checks nbr1 <= nbr2, insert
- another if-else block.
- Then, use the new if-else block to determine which case is true: "nbr1 < nbr2" or "nbr1 == nbr2"
- And print the appropriate message to the user for each condition.
- SAMPLE OUTPUT:
- Please enter two integers: 5 6
- 5 < 6
- MORE SAMPLE OUTPUT:
- Please enter two integers: 7 7
- 7 == 7
- /****** SKELETION CODE ******/
- USE YOUR SOLUTION FOR PROBLEM #1
- PROBLEM #3: Calculating a student's Grade
- In this program you will be calculating a student's Letter Grade
- for an assignment. The variables for the score and the letter grade
- have been made for you, as well as the printf and scanf for input.
- Using the skeleton code below, ADD a switch statement in the
- program that takes the score variable and prints the char variable 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.
- Use this link to help out
- https://www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm
- /****** SKELETON CODE ******/
- #include <stdio.h>
- int main (void)
- {
- // Local Declarations
- double score = 0.0;
- char grade;
- // Local Statements
- printf("Enter the test score (0-100): ");
- scanf ("%lf", &score);
- //YOUR SWITCH STATEMENT HERE
- printf("The grade is: %c\n", grade);
- return 0;
- } // main
- PROBLEM #4: Creating and Using Flags
- Often a program will need to change its execution based on some user condition or exception,
- like if the user requests to QUIT the program or there is an ERROR detected.
- As a programmer, here is what you can do to help with this: Flags.
- A flag variable can be set to a condition and a switch statement can be a handy way to determine
- what to do given that condition.
- Write a program that prompts the user to enter in an integer value 1 thru 3.
- In the case that the value is 1 or 2, print “An error occurred.\n”.
- In the case that the value is 3 print out “google i lost superbowl bet and am 8 million in debt what do i do.\n”.
- USE SWITCH-CASE TO CHECK. NOT IF-ELSE.
- After checking the cases, regardless of value of the flag, print out a message to the user
- letting them know the program is terminating with the message
- “Good luck bro, goodbye.\n”.
- PROBLEM #5: Find the median value of three values
- Using nested if/else conditions, write a program that will prompt for then take three
- unordered integer values as input. Your if/else construct should determine which value is
- the median valueof 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 an 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