算法编程

04.基本输入输出

2017-04-20  本文已影响0人  Jameslong

基本输入输出

这一节介绍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

是不是很简单呢?

上一篇 下一篇

猜你喜欢

热点阅读