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.

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

For loops For loops are controlled by a counter variable. for( c =init_value;c
Functions a group of declarations and statements that is assigned a name effectively, a named statement block usually has a value a sub-program when we.
Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman Chapter 4 (Conditional Statements) © CPCS
Switch Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply.
Chapter 9 Complex Selections and Repetitions. 9.1 INTRODUCTION Then we introduce the switch statement, which can also be used for multiway selection.
Programming Control Flow. Sequential Program S1 S2 S5 S4 S3 int main() { Statement1; Statement2; … StatementN; } Start End.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
Spring 2005, Gülcihan Özdemir Dağ Lecture 4, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 4 Outline 4.0 Reading.
Programming Variables. Named area in the computer memory, intended to contain values of a certain kind (integers, real numbers, characters etc.) They.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
CP104 Introduction to Programming Selection Structures_3 Lecture 11 __ 1 The Switch Statement The switch statement provides another means to select one.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Computer programming Lecture 4. Lecture 4: Outline Making Decisions [chap 6 – Kochan] –The if Statement –The if-else Construct –Logical Operators –Boolean.
IF-ELSE IF-ELSE STATEMENT SWITCH-CASE STATEMENT Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Switch Statement in C++. Syntax switch (selector) { case L1: statements1; break; case L2: statements2; break; … default: statements_n; } Semantics: This.
CP104 Introduction to Programming Selection structures_2 Lecture 10 __ 1 If statement (preview version) Syntax form: if ( condition) Statements else Statements.
Previously Repetition Structures While, Do-While, For.
1 C Programming Week 2 Variables, flow control and the Debugger.
CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.
Programming C for Engineers An exercise is posted on the web site! Due in one week Single submission.
Chapter 5: Structured Programming
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
CCSA 221 Programming in C CHAPTER 6 MAKING DECISIONS 1.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Functions Exercise 5. Functions a group of declarations and statements that is assigned a name  effectively, a named statement block  usually has a.
1 Agenda If Statement True/False Logical Operators Nested If / Switch Exercises & Misc.
CSCI 171 Presentation 3. Operators Instructs C to perform some operation Assignment = Mathematical Relational Logical.
UNIT 11 Random Numbers.
Principle Prog Revision. Question 1 (a) Identify errors in the following program segment and how the errors can be corrected. void main(){ constant int.
While loop Write a program that asks the user to enter a number, then displays whether this number is even or odd. The program repeats until the user quits.
Agenda  Basic Logic - Continued...  if else statements  switch Statements  Compound Conditions.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Lab 9 Exercises.
1 Today: Functions. 2 Some General Tips on Programming Write your code modularly Compile + test functionality in the process.
Making Decisions in c. 1.if statement Imagine that you could translate a statement such as “If it is not raining, then I will go swimming” into the C.
FLOW OF CONTROL In C++ the program execution starts with the first statement in the main() and ends with the last statement of main(). This is called.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 5.
 Real numbers representation - Floating Point Notation  First C Program  Variables Declaration  Data Types in C ◦ char, short, int, long, float, double,
BY ILTAF MEHDI(MCS,MCSE, CCNA) 1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI(MCS,MCSE, CCNA) 2 Programming Fundamentals Chapter.
Tutorial #4 Summer 2005.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Decisions Chapter 4.
Chapter 4 (Conditional Statements)
Condition Statements.
CS1010 Programming Methodology
Introduction to Programming
Arrays, Part 1 of 2 Topics Definition of a Data Structure
C Programming Variables.
Lec 5.
Lecture4.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Week 2 Variables, flow control and the Debugger
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CPS125 Week 5.
Control Structures Lecture 6.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CSCE 206 Lab Structured Programming in C
Control Structure គោលបំណងនៃមេរៀន អ្វីជា Control structure ?
Presentation transcript:

Problems Reads a letter grade from user and displays the corresponding range for that letter grade (A  , 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 SECENG 1111

Grades #include 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 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 int main(void) { intOper; doublex, 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 selection is not valid\n"); } return(0); }