SlideShare a Scribd company logo
1 of 46
http://eglobiotraining.com
 A programming language is an artificial
  language designed to
  communicate instructions to a machine,
  particularly a computer.
 Programming languages can be used to
  create programs that control the
  behavior of a machine and/or to
  express algorithms precisely.

            http://eglobiotraining.com
   A programming language is a notation
    for writing programs, which are
    specifications of a computation
    or algorithm.




             http://eglobiotraining.com
   A computer programming language is a
    language used to write computer
    programs, which involve a computer
    performing some kind of
    computation or algorithm and possibly
    control external devices such
    as printers, disk drives, robots, and so on.



               http://eglobiotraining.com
   Programming languages usually
    contain abstractions for defining and
    manipulating data structures or
    controlling theflow of execution.




              http://eglobiotraining.com
   As a student, I have learned that
    programming is difficult to understand
    because it has so many scripts and
    applications that can be used to run a
    program.




              http://eglobiotraining.com
   First, I find programming very hard and
    confusing because it has lots of codes
    that you need to understand for you to
    run a program.




              http://eglobiotraining.com
   Programming is a creative process done
    by programmers to instruct a computer
    on how to do a task. Programming
    languages let you use them in different
    ways, e.g. adding numbers, etc… or
    storing data on disk for later retrieval.




              http://eglobiotraining.com
 You need to consider languages to run
  your own program. DEV C++ is the most
  language that we use in programming.
 C++ is one of the most used
  programming languages in the world.
  Also known as "C with Classes".




            http://eglobiotraining.com
 In programming,
  a switch, case, select or inspect statement i
  s a type of selection control mechanism
  that exists in most imperative
  programminglanguages such
  as Pascal, Ada, C/C++, C#, Java, and so
  on
 Its purpose is to allow the value of
  a variable or expression to control the flow
  of program execution via a multiway
  branch (or "goto", one of several labels).
              http://eglobiotraining.com
switch ( <variable> ) {
case this-value:
       Code to execute if <variable> == this-value
       break;
case that-value:
    Code to execute if <variable> == that-value
    break;
...
default:
    Code to execute if <variable> does not equal the value following any of the
cases
    break;
}


    The condition of a switch statement is a value. The case says that if it has the
    value of whatever is after that case then do whatever follows the colon. The break
    is used to break out of the case statements. Break is a keyword that breaks out of
    the code block, usually surrounded by braces, which it is in. In this case, break
    prevents the program from falling through and executing the code in all the other
    case statements. An important thing to note about the switch statement is that
    the case values may only be constant integral expressions.




                                          http://eglobiotraining.com
The default case is optional, but it is wise to include it as it handles any unexpected cases. Switch
statements serves as a simple way to write long if statements when the requirements are met.
Often it can be used to process input from a user.

Above is a sample program, in which not all of the proper functions are actually declared, but
which shows how one would use switch in a program.
                                                   http://eglobiotraining.com
   This program will compile, but cannot be run
    until the undefined functions are given bodies,
    but it serves as a model (albeit simple) for
    processing input. If you do not understand this
    then try mentally putting in if statements for the
    case statements. Default simply skips out of the
    switch case construction and allows the
    program to terminate naturally. If you do not
    like that, then you can make a loop around
    the whole thing to have it wait for valid input.
    You could easily make a few small functions if
    you wish to test the code.


                 http://eglobiotraining.com
   LOOP is a pedagogical programming
    language designed by Uwe Schöning,
    along with GOTO and WHILE. The only
    operations supported in the language
    are assignment, addition and looping.




              http://eglobiotraining.com
 A loop lets you write a very simple
  statement to produce a significantly
  greater result simply by repetition.
 Before going further, you should
  understand the concept of C++'s true
  and false, because it will be necessary
  when working with loops (the conditions
  are the same as with if statements).

            http://eglobiotraining.com
 For
 While and
 Do




              http://eglobiotraining.com
For ( variable initialization; condition; variable update ) {
   Code to execute while the condition is true
}




                       http://eglobiotraining.com
 Here statement(s) may be a single
  statement or a block of statements.
  The condition may be any expression,
  and true is any nonzero value. The loop
  iterates while the condition is true.
 When the condition becomes false,
  program control passes to the line
  immediately following the loop.

            http://eglobiotraining.com
   While ( condition ) { Code to execute while
    the condition is true } The true represents a
    boolean expression which could be x == 1
    or while ( x != 7 ) (x does not equal 7). It can
    be any combination of boolean statements
    that are legal. Even, (while x ==5 || v == 7)
    which says execute the code while x equals
    five or while v equals 7. Notice that a while
    loop is the same as a for loop without the
    initialization and update sections. However,
    an empty condition is not legal for a while
    loop as it is with a for loop.

                http://eglobiotraining.com
http://eglobiotraining.com
 The do-while loop is similar to
  the while loop, except that the test
  condition occurs at the end of the loop.
 Having the test condition at the end,
  guarantees that the body of the loop
  always executes at least one time.




            http://eglobiotraining.com
do
 {
     block of code;
 }
 while (test condition);




            http://eglobiotraining.com
   Notice that the condition is tested at the
    end of the block instead of the beginning,
    so the block will be executed at least once.
    If the condition is true, we jump back to the
    beginning of the block and execute it
    again. A do..while loop is basically a
    reversed while loop. A while loop says "Loop
    while the condition is true, and execute this
    block of code", a do..while loop says
    "Execute this block of code, and loop while
    the condition is true".
               http://eglobiotraining.com
http://eglobiotraining.com
   Keep in mind that you must include a
    trailing semi-colon after the while in the
    above example. A common error is to
    forget that a do..while loop must be
    terminated with a semicolon (the other
    loops should not be terminated with a
    semicolon, adding to the confusion).
    Notice that this loop will execute once,
    because it automatically executes
    before checking the condition.
               http://eglobiotraining.com
http://eglobiotraining.com
#include <iostream>

int main()
{
   using namespace std;

    // nSelection must be declared outside do/while loop
    int nSelection;

    do
    {
       cout << "Please make a selection: " << endl;
       cout << "1) Addition" << endl;
       cout << "2) Subtraction" << endl;
       cout << "3) Multiplication" << endl;
       cout << "4) Division" << endl;
       cin >> nSelection;
    } while (nSelection != 1 && nSelection != 2 &&
         nSelection != 3 && nSelection != 4);

    // do something with nSelection here
    // such as a switch statement

    return 0;
}
                                  http://eglobiotraining.com
#include <iostream>
using namespace std;
 int main()
{
   int nSelection;
   double var1, var2;

  do
  {
    cout << "Please make a selection: " << endl;
    cout << "1) Addition" << endl;
    cout << "2) Subtraction" << endl;
    cout << "3) Multiplication" << endl;
    cout << "4) Division" << endl;
    cin >> nSelection;
  }

  while (nSelection != 1 && nSelection != 2 &&
      nSelection != 3 && nSelection != 4);

   if (nSelection == 1)
       {
       cout << "Please enter the first whole number ";
       cin >> var1;
       cout << "Please enter the second whole number ";
       cin >> var2;
      cout << "The result is " << (var1+var2) << endl;
      }                                     http://eglobiotraining.com
if (nSelection == 2)
      {
        cout << "Please enter the first whole number ";
        cin >> var1;
        cout << "Please enter the second whole number ";
        cin >> var2;
       cout << "The result is " << (var1-var2) << endl;
       }
    if (nSelection == 3)
        {
        cout << "Please enter the first whole number ";
        cin >> var1;
        cout << "Please enter the second whole number ";
        cin >> var2;
       cout << "The result is " << (var1*var2) << endl;
       }
      if (nSelection == 4)
        {
        cout << "Please enter the first whole number ";
        cin >> var1;
        cout << "Please enter the second whole number ";
        cin >> var2;
       cout << "The result is " << (var1/var2) << endl;
        }

    return 0;
}




                                      http://eglobiotraining.com
else if (nSelection == 2)
     {
         cout << "Please enter the first whole number ";
         cin >> var1;
         cout << "Please enter the second whole number ";
         cin >> var2;
         cout << "The result is " << (var1-var2) << endl;
     }
     else if (nSelection == 3)
     {
         cout << "Please enter the first whole number ";
         cin >> var1;
         cout << "Please enter the second whole number ";
         cin >> var2;
         cout << "The result is " << (var1*var2) << endl;
     }
     else if (nSelection == 4)
     {
         cout << "Please enter the first whole number ";
         cin >> var1;
         cout << "Please enter the second whole number ";
         cin >> var2;
         cout << "The result is " << (var1/var2) << endl;
     }
else
     {
         return 0;
     }
   }
}

                                http://eglobiotraining.com
#include <iostream>

using namespace std; // So the program can see cout and endl

int main()
{
  // The loop goes while x < 10, and x increases by one every loop
  for ( int x = 0; x < 10; x++ ) {
    // Keep in mind that the loop condition checks
    // the conditional statement before it loops again.
    // consequently, when x equals 10 the loop breaks.
    // x is updated before the condition is checked.
    cout<< x <<endl;
  }
  cin.get();
}


                      http://eglobiotraining.com
#include <iostream>


using namespace std;


int main ()

{

    int score;


    cout << "What was your score?";

    cin >> score;


    if (score <= 30)

    {
        cout << "nOuch, less than 30...!";

    }




                                     http://eglobiotraining.com
else if (score <= 50)

 {

     cout << "nYou score aint great mate..";

 }

 else if (score <= 80)

 {

     cout << "nYour pretty good, well done man!";

 }

 else if (score <= 100)

 {

     cout << "nYou got to the top!!!";

 }



                                 http://eglobiotraining.com
else

    {

        cout << "nYou cant score higher than 100!!! Cheater!!!!";

    }



    cin.ignore();

    cin.get();



    return 0;

}




                               http://eglobiotraining.com
#include <iostream>

using namespace std;

int main(){
cout << "Enter a number between 1 and 5!" << endl;
int number;
cin >> number;
if(number == 1){
cout << "one";
}
else if(number == 2){
cout << "two";
}
else if(number == 3){
cout << "three";
}
else if(number == 4){
cout << "four";
}
else if(number == 5){
cout << "five";
}
else{
cout << number << " is not between 1 and 5!";
}
cout << endl;
system("pause");
}




                                 http://eglobiotraining.com
#include <stdlib.h>
#include <stdio.h>

int main(void) {
  int n;
  printf("Please enter a number: ");
  scanf("%d", &n);
  switch (n) {
    case 1: {
      printf("n is equal to 1!n");
      break;
    }
    case 2: {
      printf("n is equal to 2!n");
      break;
    }
    case 3: {
      printf("n is equal to 3!n");
      break;
    }
    default: {
      printf("n isn't equal to 1, 2, or 3.n");
      break;
    }
  }
  system("PAUSE");
  return 0;
}

                                             http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
http://eglobiotraining.com
   Submitted to:
    Professor Erwin Globio

   Submitted by:
    Charlaine J. Astillas

BM 10203

               http://eglobiotraining.com

More Related Content

What's hot

Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)jewelyngrace
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJanlay Wu
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming LanguageMahantesh Devoor
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loopsbsdeol28
 
Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch casesMeoRamos
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statementsnobel mujuji
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb scriptNilanjan Saha
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinarurumedina
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsHock Leng PUAH
 

What's hot (20)

Loops in JavaScript
Loops in JavaScriptLoops in JavaScript
Loops in JavaScript
 
Iteration
IterationIteration
Iteration
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak Typing
 
Looping statements
Looping statementsLooping statements
Looping statements
 
C++ loop
C++ loop C++ loop
C++ loop
 
Loops in c
Loops in cLoops in c
Loops in c
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
What JS? Itself
What JS? ItselfWhat JS? Itself
What JS? Itself
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Loop control in c++
Loop control in c++Loop control in c++
Loop control in c++
 
Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch cases
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb script
 
Looping statement
Looping statementLooping statement
Looping statement
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional Logics
 

Viewers also liked

Data types and Operators
Data types and OperatorsData types and Operators
Data types and OperatorsMohamed Samy
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Viewers also liked (6)

Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...
Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...
Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer...
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to Switch case and looping

Similar to Switch case and looping (20)

C++ programming
C++ programmingC++ programming
C++ programming
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angeli
 
Computer programming
Computer programmingComputer programming
Computer programming
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajang
 
Survelaine murillo ppt
Survelaine murillo pptSurvelaine murillo ppt
Survelaine murillo ppt
 
Deguzmanpresentationprogramming
DeguzmanpresentationprogrammingDeguzmanpresentationprogramming
Deguzmanpresentationprogramming
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Vb (2)
Vb (2)Vb (2)
Vb (2)
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
neiljaysonching
neiljaysonchingneiljaysonching
neiljaysonching
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 

Switch case and looping

  • 2.  A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer.  Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely. http://eglobiotraining.com
  • 3. A programming language is a notation for writing programs, which are specifications of a computation or algorithm. http://eglobiotraining.com
  • 4. A computer programming language is a language used to write computer programs, which involve a computer performing some kind of computation or algorithm and possibly control external devices such as printers, disk drives, robots, and so on. http://eglobiotraining.com
  • 5. Programming languages usually contain abstractions for defining and manipulating data structures or controlling theflow of execution. http://eglobiotraining.com
  • 6. As a student, I have learned that programming is difficult to understand because it has so many scripts and applications that can be used to run a program. http://eglobiotraining.com
  • 7. First, I find programming very hard and confusing because it has lots of codes that you need to understand for you to run a program. http://eglobiotraining.com
  • 8. Programming is a creative process done by programmers to instruct a computer on how to do a task. Programming languages let you use them in different ways, e.g. adding numbers, etc… or storing data on disk for later retrieval. http://eglobiotraining.com
  • 9.  You need to consider languages to run your own program. DEV C++ is the most language that we use in programming.  C++ is one of the most used programming languages in the world. Also known as "C with Classes". http://eglobiotraining.com
  • 10.  In programming, a switch, case, select or inspect statement i s a type of selection control mechanism that exists in most imperative programminglanguages such as Pascal, Ada, C/C++, C#, Java, and so on  Its purpose is to allow the value of a variable or expression to control the flow of program execution via a multiway branch (or "goto", one of several labels). http://eglobiotraining.com
  • 11. switch ( <variable> ) { case this-value: Code to execute if <variable> == this-value break; case that-value: Code to execute if <variable> == that-value break; ... default: Code to execute if <variable> does not equal the value following any of the cases break; } The condition of a switch statement is a value. The case says that if it has the value of whatever is after that case then do whatever follows the colon. The break is used to break out of the case statements. Break is a keyword that breaks out of the code block, usually surrounded by braces, which it is in. In this case, break prevents the program from falling through and executing the code in all the other case statements. An important thing to note about the switch statement is that the case values may only be constant integral expressions. http://eglobiotraining.com
  • 12. The default case is optional, but it is wise to include it as it handles any unexpected cases. Switch statements serves as a simple way to write long if statements when the requirements are met. Often it can be used to process input from a user. Above is a sample program, in which not all of the proper functions are actually declared, but which shows how one would use switch in a program. http://eglobiotraining.com
  • 13. This program will compile, but cannot be run until the undefined functions are given bodies, but it serves as a model (albeit simple) for processing input. If you do not understand this then try mentally putting in if statements for the case statements. Default simply skips out of the switch case construction and allows the program to terminate naturally. If you do not like that, then you can make a loop around the whole thing to have it wait for valid input. You could easily make a few small functions if you wish to test the code. http://eglobiotraining.com
  • 14. LOOP is a pedagogical programming language designed by Uwe Schöning, along with GOTO and WHILE. The only operations supported in the language are assignment, addition and looping. http://eglobiotraining.com
  • 15.  A loop lets you write a very simple statement to produce a significantly greater result simply by repetition.  Before going further, you should understand the concept of C++'s true and false, because it will be necessary when working with loops (the conditions are the same as with if statements). http://eglobiotraining.com
  • 16.  For  While and  Do http://eglobiotraining.com
  • 17. For ( variable initialization; condition; variable update ) { Code to execute while the condition is true } http://eglobiotraining.com
  • 18.  Here statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true.  When the condition becomes false, program control passes to the line immediately following the loop. http://eglobiotraining.com
  • 19. While ( condition ) { Code to execute while the condition is true } The true represents a boolean expression which could be x == 1 or while ( x != 7 ) (x does not equal 7). It can be any combination of boolean statements that are legal. Even, (while x ==5 || v == 7) which says execute the code while x equals five or while v equals 7. Notice that a while loop is the same as a for loop without the initialization and update sections. However, an empty condition is not legal for a while loop as it is with a for loop. http://eglobiotraining.com
  • 21.  The do-while loop is similar to the while loop, except that the test condition occurs at the end of the loop.  Having the test condition at the end, guarantees that the body of the loop always executes at least one time. http://eglobiotraining.com
  • 22. do { block of code; } while (test condition); http://eglobiotraining.com
  • 23. Notice that the condition is tested at the end of the block instead of the beginning, so the block will be executed at least once. If the condition is true, we jump back to the beginning of the block and execute it again. A do..while loop is basically a reversed while loop. A while loop says "Loop while the condition is true, and execute this block of code", a do..while loop says "Execute this block of code, and loop while the condition is true". http://eglobiotraining.com
  • 25. Keep in mind that you must include a trailing semi-colon after the while in the above example. A common error is to forget that a do..while loop must be terminated with a semicolon (the other loops should not be terminated with a semicolon, adding to the confusion). Notice that this loop will execute once, because it automatically executes before checking the condition. http://eglobiotraining.com
  • 27. #include <iostream> int main() { using namespace std; // nSelection must be declared outside do/while loop int nSelection; do { cout << "Please make a selection: " << endl; cout << "1) Addition" << endl; cout << "2) Subtraction" << endl; cout << "3) Multiplication" << endl; cout << "4) Division" << endl; cin >> nSelection; } while (nSelection != 1 && nSelection != 2 && nSelection != 3 && nSelection != 4); // do something with nSelection here // such as a switch statement return 0; } http://eglobiotraining.com
  • 28. #include <iostream> using namespace std; int main() { int nSelection; double var1, var2; do { cout << "Please make a selection: " << endl; cout << "1) Addition" << endl; cout << "2) Subtraction" << endl; cout << "3) Multiplication" << endl; cout << "4) Division" << endl; cin >> nSelection; } while (nSelection != 1 && nSelection != 2 && nSelection != 3 && nSelection != 4); if (nSelection == 1) { cout << "Please enter the first whole number "; cin >> var1; cout << "Please enter the second whole number "; cin >> var2; cout << "The result is " << (var1+var2) << endl; } http://eglobiotraining.com
  • 29. if (nSelection == 2) { cout << "Please enter the first whole number "; cin >> var1; cout << "Please enter the second whole number "; cin >> var2; cout << "The result is " << (var1-var2) << endl; } if (nSelection == 3) { cout << "Please enter the first whole number "; cin >> var1; cout << "Please enter the second whole number "; cin >> var2; cout << "The result is " << (var1*var2) << endl; } if (nSelection == 4) { cout << "Please enter the first whole number "; cin >> var1; cout << "Please enter the second whole number "; cin >> var2; cout << "The result is " << (var1/var2) << endl; } return 0; } http://eglobiotraining.com
  • 30. else if (nSelection == 2) { cout << "Please enter the first whole number "; cin >> var1; cout << "Please enter the second whole number "; cin >> var2; cout << "The result is " << (var1-var2) << endl; } else if (nSelection == 3) { cout << "Please enter the first whole number "; cin >> var1; cout << "Please enter the second whole number "; cin >> var2; cout << "The result is " << (var1*var2) << endl; } else if (nSelection == 4) { cout << "Please enter the first whole number "; cin >> var1; cout << "Please enter the second whole number "; cin >> var2; cout << "The result is " << (var1/var2) << endl; } else { return 0; } } } http://eglobiotraining.com
  • 31. #include <iostream> using namespace std; // So the program can see cout and endl int main() { // The loop goes while x < 10, and x increases by one every loop for ( int x = 0; x < 10; x++ ) { // Keep in mind that the loop condition checks // the conditional statement before it loops again. // consequently, when x equals 10 the loop breaks. // x is updated before the condition is checked. cout<< x <<endl; } cin.get(); } http://eglobiotraining.com
  • 32. #include <iostream> using namespace std; int main () { int score; cout << "What was your score?"; cin >> score; if (score <= 30) { cout << "nOuch, less than 30...!"; } http://eglobiotraining.com
  • 33. else if (score <= 50) { cout << "nYou score aint great mate.."; } else if (score <= 80) { cout << "nYour pretty good, well done man!"; } else if (score <= 100) { cout << "nYou got to the top!!!"; } http://eglobiotraining.com
  • 34. else { cout << "nYou cant score higher than 100!!! Cheater!!!!"; } cin.ignore(); cin.get(); return 0; } http://eglobiotraining.com
  • 35. #include <iostream> using namespace std; int main(){ cout << "Enter a number between 1 and 5!" << endl; int number; cin >> number; if(number == 1){ cout << "one"; } else if(number == 2){ cout << "two"; } else if(number == 3){ cout << "three"; } else if(number == 4){ cout << "four"; } else if(number == 5){ cout << "five"; } else{ cout << number << " is not between 1 and 5!"; } cout << endl; system("pause"); } http://eglobiotraining.com
  • 36. #include <stdlib.h> #include <stdio.h> int main(void) { int n; printf("Please enter a number: "); scanf("%d", &n); switch (n) { case 1: { printf("n is equal to 1!n"); break; } case 2: { printf("n is equal to 2!n"); break; } case 3: { printf("n is equal to 3!n"); break; } default: { printf("n isn't equal to 1, 2, or 3.n"); break; } } system("PAUSE"); return 0; } http://eglobiotraining.com
  • 46. Submitted to: Professor Erwin Globio  Submitted by: Charlaine J. Astillas BM 10203 http://eglobiotraining.com