40 likes | 198 Views
Problems. Reads a letter grade from user and displays the corresponding range for that letter grade (A 90-100, B80-89, C70-79, D60-69, otherwise F) Modify the above problem to accept lower or uppercase letter grades.
E N D
Problems • Reads a letter grade from user and displays the corresponding range for that letter grade (A 90-100, B80-89, C70-79, D60-69, otherwise F) • Modify the above problem to accept lower or uppercase letter grades. • Write a program for a simple calculator which asks the user to select which operation (+, -, *, /, %), then asks for two numbers, displays the result CENG 111
Grades • #include <stdio.h> • int main(void) { • char LtrGrd; • printf("Please enter Letter Grade: "); • scanf("%c", &LtrGrd); • switch (LtrGrd) { • case 'A': • printf("Your grade is between 90 and 100\n"); • break; • case 'B': • printf("Your grade is between 80 and 89\n"); • break; • case 'C': • printf("Your grade is between 70 and 79\n"); • break; • case 'D': • printf("Your grade is between 60 and 69\n"); • break; • case 'F': • printf("Your grade is less than 60\n"); • break; • default: • printf("The letter grade entered is not valid\n"); • } • return(0); • }
Grades 2 • #include <stdio.h> • int main(void) { • char LtrGrd; • printf("Please enter Letter Grade: "); • scanf("%c", &LtrGrd); • switch (LtrGrd) { • case 'A': • case 'a': • printf("Your grade is between 90 and 100\n"); • break; • case 'B': • case 'b': • printf("Your grade is between 80 and 89\n"); • break; • case 'C': • case 'c': • printf("Your grade is between 70 and 79\n"); • break; • case 'D': • case 'd': • printf("Your grade is between 60 and 69\n"); • break; • case 'F': • case 'f': • printf("Your grade is less than 60\n"); • break; • default: • printf("The letter grade entered is not valid\n"); • } • return(0); • }
Calculator #include <stdio.h> int main(void) { intOper; double x, y; printf("(1) Add\n"); printf("(2) Subtract\n"); printf("(3) Multiply\n"); printf("(4) Divide\n"); printf("Please enter your choice: "); scanf("%d", &Oper); printf("Please enter two operands: "); scanf("%lf%lf", &x, &y); switch (Oper) { case 1: printf("A + B = %.2f\n", x+y); break; case 2: printf("A - B = %.2f\n", x-y); break; case 3: printf("A * B = %.2f\n", x*y); break; case 4: printf("A / B = %.2f\n", x/y); break; default: printf("The letter grade is not valid\n"); } return(0); }