Primer_Five
来源:互联网 发布:程序员培训班怎么样 编辑:程序博客网 时间:2024/04/27 20:41
#include <iostream>using namespace std;int main(){ int num_1,num_2,i,add=0; cout << "Please enter the first numble : "<<endl; cin >> num_1; cout << "Please enter a number greater than the first number:"<<endl; cin >> num_2; for(i=num_1;i<=num_2;i++) { add+=i; } cout << "The result is :"<<add<<endl; return 0;}
#include <iostream>using namespace std;int main(){ int num,add=0; while (num!=0) { cout << "please enter numble,If you want to end input, enter 0:" << endl; cin >> num; add+=num; cout << "All the accumulated input is :"<<add<<endl; } return 0;}
#include <iostream>using namespace std;int main(){ float Dap_Interest=0,Cleo_Interest=0; int i=0; do { Dap_Interest+=100*0.1; Cleo_Interest+=((100+Cleo_Interest)*0.05); ++i; } while (Dap_Interest>Cleo_Interest); cout << "After the "<<i<<" year,the interest of Cleo is greater than Daphne."<<endl; return 0;}
#include <iostream>#include <string>using namespace std;struct car{ string manu_f; int year;};int main(){ int n,i; cout << "How many cars do you wish to catalog? "<<endl; cin >> n; cin.get(); car *car_n = new car[n]; for(i=0;i<n;i++) { cout<<"Cae #"<<i+1<<":"<<endl; cout<<"Please enter the make:"; getline(cin,car_n[i].manu_f); cout <<endl; cout << "Please enter the year made :"; cin >> car_n[i].year; cin.get(); cout << endl; } cout << "Here is your collection:"<<endl; for(i=0;i<n;i++) { cout <<car_n[i].year<<" "<<car_n[i].manu_f<<endl; } return 0;}
//数字输入之后要在后面加上cin.get(),不然下一个输入会直接读取上一次输入数字后留下的终止符。
#include <iostream>#include <cstring>using namespace std;int main(){ const int Size=100; char word[Size]; int i=0; cout << "Enter words (to stop,type the word done):"; while (cin >> word&&strcmp(word,"done")) { ++i; } return 0;}
0 0