04.基本输入输出

基本输入输出

这一节介绍C++的基本输入输出语句,很简单,只要用到"cout<<"和"cin>>"就可以了,其实coutcin都是标准输入输出流对象,他们的头文件是,所以要想实现输入输出我们都会#include ,下面举个简单的例子
提醒用户输入自己各科成绩,然后算出平均值输出

#include
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

是不是很简单呢?

你可能感兴趣的:(04.基本输入输出)