C/C++教程

C++ primer plus程序2.2《carrots.cpp》

本文主要是介绍C++ primer plus程序2.2《carrots.cpp》,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

//程序清单2.2
//carrots.cpp  --  food processing program
//uses and display a variable
#include <iostream>

int main()
{
    using namespace std;
    
    int carrots;                                            //declare an interger variable
    
    carrots = 25;                                         //assign a value to the variable 
    
    cout<<"I have";                                 
    
    cout<<carrots;                                       //display the value of the variable 
    
    cout<<"carrots";
    
    cout<<endl;
    
    carrots=carrots - 1;                                 //modify the variable
    
    cout<<"Crunch, crunch. Now I have " << carrots << "carrots."<<endl;
    
    return 0;
    
}
 

这篇关于C++ primer plus程序2.2《carrots.cpp》的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!