Switch case and looping

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
1 von 46

Recomendados

Switch case and looping new von
Switch case and looping newSwitch case and looping new
Switch case and looping newaprilyyy
426 views51 Folien
Macasu, gerrell c. von
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
232 views51 Folien
Switch case and looping von
Switch case and loopingSwitch case and looping
Switch case and loopingaprilyyy
444 views51 Folien
Switch case and looping kim von
Switch case and looping kimSwitch case and looping kim
Switch case and looping kimkimberly_Bm10203
583 views54 Folien
Switch case and looping jam von
Switch case and looping jamSwitch case and looping jam
Switch case and looping jamJamaicaAubreyUnite
343 views50 Folien
My final requirement von
My final requirementMy final requirement
My final requirementkatrinaguevarra29
277 views51 Folien

Más contenido relacionado

Was ist angesagt?

Loops in JavaScript von
Loops in JavaScriptLoops in JavaScript
Loops in JavaScriptFlorence Davis
1.2K views13 Folien
Iteration von
IterationIteration
IterationLiam Dunphy
9.5K views29 Folien
Final project powerpoint template (fndprg) (1) von
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)jewelyngrace
379 views20 Folien
C lecture 4 nested loops and jumping statements slideshare von
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
3K views15 Folien
Yeahhhh the final requirement!!! von
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
257 views52 Folien
JavaScript Loop: Optimization of Weak Typing von
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJanlay Wu
988 views20 Folien

Was ist angesagt?(20)

Final project powerpoint template (fndprg) (1) von jewelyngrace
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
jewelyngrace379 views
C lecture 4 nested loops and jumping statements slideshare von Gagan Deep
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
Gagan Deep3K views
Yeahhhh the final requirement!!! von olracoatalub
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
olracoatalub257 views
JavaScript Loop: Optimization of Weak Typing von Janlay Wu
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak Typing
Janlay Wu988 views
Presentation on nesting of loops von bsdeol28
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol288.7K views
Looping and switch cases von MeoRamos
Looping and switch casesLooping and switch cases
Looping and switch cases
MeoRamos4.2K views
Javascript conditional statements von nobel mujuji
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
nobel mujuji3.5K views
Conditional statements in vb script von Nilanjan Saha
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb script
Nilanjan Saha799 views
Looping statement von ilakkiya
Looping statementLooping statement
Looping statement
ilakkiya3.8K views
Fundamentals of prog. by rubferd medina von rurumedina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
rurumedina249 views
Spf Chapter5 Conditional Logics von Hock Leng PUAH
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional Logics
Hock Leng PUAH1.2K views

Destacado

Learning the C Language von
Learning the C LanguageLearning the C Language
Learning the C LanguagenTier Custom Solutions
2.4K views188 Folien
Data types and Operators von
Data types and OperatorsData types and Operators
Data types and OperatorsMohamed Samy
3.8K views18 Folien
Switch Case in C Programming von
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
6.2K views14 Folien
Stay Up To Date on the Latest Happenings in the Boardroom: Recommended Summer... von
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...Stanford GSB Corporate Governance Research Initiative
254.1K views9 Folien
Hype vs. Reality: The AI Explainer von
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
497.8K views28 Folien
Study: The Future of VR, AR and Self-Driving Cars von
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
869.7K views28 Folien

Similar a Switch case and looping

C++ programming von
C++ programmingC++ programming
C++ programmingviancagerone
953 views42 Folien
My programming final proj. (1) von
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
296 views49 Folien
C++ programming von
C++ programmingC++ programming
C++ programmingviancagerone
20.5K views42 Folien
Switch case looping von
Switch case loopingSwitch case looping
Switch case loopingCherimay Batallones
417 views60 Folien
Fundamentals of programming angeli von
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angelibergonio11339481
534 views69 Folien
Computer programming von
Computer programmingComputer programming
Computer programmingXhyna Delfin
363 views24 Folien

Similar a Switch case and looping(20)

My programming final proj. (1) von aeden_brines
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
aeden_brines296 views
Deguzmanpresentationprogramming von deguzmantrisha
DeguzmanpresentationprogrammingDeguzmanpresentationprogramming
Deguzmanpresentationprogramming
deguzmantrisha297 views
FP 201 - Unit 3 Part 2 von rohassanie
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie510 views
OpenGurukul : Language : C++ Programming von Open Gurukul
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
Open Gurukul4.6K views
Complete C++ programming Language Course von Vivek chan
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
Vivek chan5.1K views

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