h4344

C++ Example

Jan 26th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace::std;
  4.  
  5. void prototypefunction();
  6.  
  7. int main(){
  8.    
  9.     int choice;
  10.    
  11.     int list[1];
  12.    
  13.     list[0] = 1;
  14.     list[1] = 2;
  15.    
  16.     int x = list[0];
  17.     int y = list[1];
  18.     int z = list[0] + list[1];    
  19.    
  20.     system("cls");
  21.     cout << "Simple C++ example's, coded by Harry Laurent" << endl;
  22.     cout << "--------------------------------------------" << endl;
  23.     cout << "1. Call a simple function to display a message." << endl;
  24.     cout << "2. Simple variables math." << endl;
  25.     cout << "3. Exit Program" << endl;
  26.    
  27.     cin >> choice;
  28.    
  29.     if(choice == 1){
  30.          prototypefunction();          
  31.     }
  32.    
  33.     if(choice == 2){
  34.          system("cls");
  35.          cout << "The value of x + y = z, z = " << z << endl;
  36.          system("pause");
  37.          return main();
  38.     }
  39.    
  40.     if(choice == 3){
  41.          exit(1);          
  42.     }    
  43.    
  44.     if(choice != 1 && choice != 2 && choice != 3 || choice == 'null'){
  45.          system("cls");
  46.          cout << "Invalid option, please try again." << endl;
  47.          system("pause");
  48.          
  49.          return main();
  50.     }    
  51.    
  52.     return main();
  53.    
  54. }
  55.  
  56. void prototypefunction(){
  57.      
  58.      system("cls");
  59.      cout << "This message is displayed using a function" << endl;
  60.      system("pause");
  61.      
  62.      return;    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment