This Blog is dedicated to Sir Johnson Lin
Learn flow chart from C language , master C with the chart!

C++ 基本 使用是非決策功能 C++ basic function , Yes-No decision (if) introduction



D:\cppCodes\HelloIf\HelloIf.c++
 1 //++++++++++++++++++++++++++
 2  //      HelloIf.cpp
 3  //++++++++++++++++++++++++++
 4  
 5  ///#include headers
 6  #include <iostream>
 7  
 8  ///USING
 9  using namespace std;
10  
11  ///mainentry
12  int main()
13  {
14      ///declare variables
15      int iMyInt = 88;               // Integer
16      float fMyFloat = 1.68;    // Floating point number
17      char cMyChar = 'A';         // Character
18      string sMyString = "my text string ";     // txt string
19      char caMyString[] = "my character array"; // txt string 
20      char cMyInputChar   ;         // Character
21      
22      ///Display 1st_time
23      cout << "Int = " << iMyInt << endl;
24      cout << "Float = " << fMyFloat << endl;
25      cout << "Char = " << cMyChar << endl;
26      cout << "String = " << sMyString << endl;
27      cout << "CharArray = " << caMyString << endl;
28      
29      ///Prompt Input
30      cout << endl << "Key 'y' to show again,  =  " ;
31      
32      ///Keyin
33      cin >> cMyInputChar;
34      
35      ///char 'y'?
36      if (cMyInputChar =='y')
37      {
38          ///Display 2nd_time
39          cout << "Int = " << iMyInt << endl;
40          cout << "Float = " << fMyFloat << endl;
41          cout << "Char = " << cMyChar << endl;
42          cout << "String = " << sMyString << endl;
43          cout << "CharArray = " << caMyString << endl;
44          
45          ///+
46      }//end if
47      
48      ///mainend
49      return 0;
50  }//end main()
51  

@ 下載程式碼 Download source code

沒有留言:

張貼留言