04.基本輸入輸出

基本輸入輸出

這一節介紹C++的基本輸入輸出語句,很簡單,只要用到"cout<<"和"cin>>"就可以了,其實coutcin都是標準輸入輸出流對象,他們的頭文件是<iostream>,所以要想實現輸入輸出我們都會#include<iostream> ,下面舉個簡單的例子
提醒用戶輸入自己各科成績,然后算出平均值輸出

#include<iostream>
using namespace std;
const float pi = 3.14;
int main(){
    float chinese_score;
    float math_score;
    float engilsh_score;
    
    cout << "please input your chinese score:";
    cin >> chinese_score;
    cout << "please input your math score:";
    cin >> math_score;
    cout << "please input your english score:";
    cin >> engilsh_score;
    cout << "Your average score is " << (chinese_score + math_score + engilsh_score) / 3 << endl;
    
    return 0;
}
Paste_Image.png

是不是很簡單呢?

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容