1 / 4

Problems

Problems. Reads a letter grade from user and displays the corresponding range for that letter grade (A 90-100, B80-89, C70-79, D60-69, otherwise F) Modify the above problem to accept lower or uppercase letter grades.

palmer
Download Presentation

Problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problems • Reads a letter grade from user and displays the corresponding range for that letter grade (A 90-100, B80-89, C70-79, D60-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

  2. 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); • }

  3. 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); • }

  4. 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); }

More Related