文末有福利 switch case
#include<iostream> using namespace std; int main() { enum DaysOfWeek { Sunday = 0, //这里千万不能是分号 Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } ; cout<< "找出各天是以哪个星星命名的!"<<endl; cout<<"输入一个星期的数字(sunday=0)" ; int Day = 0; cin>>Day ; switch(Day) { case Sunday: //这里用冒号 cout<<"Sunday was named after the Sun(太阳)"<<endl; break; case Monday: cout<<"Monday was named after the Moon(月亮)"<<endl; break; case Tuesday: cout<<"Tuesday was named after the Mars(火星)"<<endl; break; case Wednesday: cout<<"Wednesday was named after the Mercury(水星)"<<endl; break; case Thursday: cout<<"Thursday was named after the Jupiter(木星)"<<endl; break; case Friday: cout<<"Friday was named after the Venus(金星)"<<endl; break; case Saturday: cout<<"Saturday was named after the Saturn(土星)"<<endl; break; default: cout<<"输入错误,请重新输入!!!"<<endl; break; } return 0; }运行结果 while循环
#include<iostream> using namespace std; int main() { char anjian='e'; while(anjian != 'x') { cout<<"请输入两个数:"<<endl; int shu1 =0,shu2=0; cin >>shu1; cin >>shu2; cout<<shu1<<"×"<<shu2<<"="<<shu1*shu2<<endl; cout<<shu1<<"+"<<shu2<<"="<<shu1+shu2<<endl; cout<<"按下 x 退出计算,按下其他键重新计算"<<endl; cin>>anjian; } cout << "再见!"<<endl; return 0; }运行结果 goto循环
#include<iostream> using namespace std; int main() { JumpToPoint: int shu1 = 0,shu2 = 0; cout<<"请输入两个数:"<<endl; cin>>shu1; cin>>shu2; cout<<shu1<<"×"<<shu2<<"="<<shu1*shu2<<endl; cout<<shu1<<"+"<<shu2<<"="<<shu1+shu2<<endl; cout<<"请问您是都需要进行下一次操作(y/n)"<<endl; char Repeat = 'y'; cin>>Repeat; if (Repeat == 'y') goto JumpToPoint; cout<<"再见!"<<endl; return 0; }运行结果 do while
#include<iostream> using namespace std; int main() { char anjian='e'; do { cout<<"请输入两个数:"<<endl; int shu1 =0,shu2=0; cin >>shu1; cin >>shu2; cout<<shu1<<"×"<<shu2<<"="<<shu1*shu2<<endl; cout<<shu1<<"+"<<shu2<<"="<<shu1+shu2<<endl; cout<<"按下 e 退出计算,按下其他键重新计算"<<endl; cin>>anjian; }while (anjian != 'e'); cout << "再见!"<<endl; return 0; }运行结果 for循环才重复执行计算
**#include<iostream> using namespace std; int main() { for(char anjian = 'm';(anjian !='x');) { cout<<"请输入两个数:"<<endl; int shu1 =0,shu2=0; cin >>shu1; cin >>shu2; cout<<shu1<<"×"<<shu2<<"="<<shu1*shu2<<endl; cout<<shu1<<"+"<<shu2<<"="<<shu1+shu2<<endl; cout<<"按下 x 退出计算,按下其他键重新计算"<<endl; cin>>anjian; } cout << "再见!"<<endl; return 0; }**运行结果 福利语句
#include<iostream> #include<math.h> using namespace std; int main() { float y, x, z; cout<<"那一天"<<endl; cout<<"第一次在路上看见你"<<endl; cout<<"远远地望着你的容颜"<<endl; cout<<"髣髴兮若轻云之蔽月,"<<endl; cout<<"飘飖兮若流风之回雪。"<<endl; cout<<"远而望之,皎若太阳升朝霞;"<<endl; cout<<"迫而察之,灼若芙蕖出渌波。"<<endl; cout<<"一直都不敢靠近"<<endl; cout<<"有句话一直埋在我心里"<<endl; cout<<"想对你说:"<<endl; for (double y = 2.5; y >= -1.6; y = y - 0.2) { for (double x = -3; x <= 4.8; x = x + 0.1) { (pow((x*x + y*y - 1), 3) <= 3.6*x*x*y*y*y || (x>-2.4 && x<-2.1 && y<1.5 && y>-1) || (((x<2.5 && x>2.2) || (x>3.4 && x<3.7)) && y>-1 && y<1.5) || (y>-1 && y<-0.6 && x<3.7 && x>2.2)) ? printf("*") : printf(" "); } cout<<endl; } getchar(); }运行结果 拿去跟好基友表白吧啊哈!
1123093