tikimyster

Examples for V

Jul 3rd, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     /*This is a variable there are int, char, float, double, bool (true false) and more*/
  8.  
  9.     /*------------------variables---------------------*/
  10.  
  11.     int x = 0; //this is an integer
  12.     char = c; // this is a character variable
  13.     bool frogs = true; //these can be set to true or fasle
  14.     double a = 0; //this is just a bigger storage variable than an int.
  15.  
  16.     /*------------------end variables---------------------*/
  17.  
  18.     /*--------------If statement Begin---------------------*/
  19.  
  20.     if (x = 2)
  21.     { /* this isn't required if the if statement is all on one line so the next else if I wont use them */
  22.         cout << "hi";
  23.     }
  24.     else if(x = 7)
  25.         cout << "this is fun";
  26.     else
  27.         cout << "bye";
  28.  
  29.     /*--------------If statement END---------------------*/
  30.  
  31.     /*--------------switch statement Begin---------------------*/
  32.     switch (c) /* Case statement / switch statement pretty much like an if else statement but will only work when the right case happens */
  33.     {
  34.         case 1: //this will happen when the character c = 1
  35.             x = x +1; //this is the same as x++;
  36.             break; //break gets you out of loops or in this case the switch statment.
  37.         case 2: //this will happen when the character c = 2
  38.             x = x - 1; //this is the same as x--;
  39.             break;
  40.         default: //this will happen when none of the other cases matched the given.
  41.             break;
  42.     }
  43.  
  44.     /*--------------switch statement end---------------------*/
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment