if语句
#include<iostream>
using namespace std;
int main(){
int score = 0;
cout << "请输入一个分数" << endl;
cin >> score;
cout << "您的分数为:" << score <<endl;
if (score > 90)
{
cout << "恭喜您获得A!" << endl;
}
else if (score > 80)
{
cout << "恭喜您获得B!" << endl;
}
else if (score > 60)
{
cout << "恭喜您获得C!" << endl;
}
else
{
cout << "不及格!" << endl;
}
}
switch语句
#include<iostream>
using namespace std;
int main(){
int score = 0;
cout << "请给电影打分" << endl;
cin >> score;
cout << "您打分数为:" << score <<endl;
switch(score)
{
case 10:
cout << "您认为是经典电影" << endl;
break;
case 9:
cout << "您认为是经典电影" << endl;
break;
case 8:
cout << "您认为是非常好的电影" << endl;
break;
case 7:
cout << "您认为是非常好的电影" << endl;
break;
case 6:
cout << "您认为电影一般" << endl;
break;
case 5:
cout << "您认为电影一般" << endl;
break;
default:
cout << "烂片" << endl;
}
}
while语句
#include<iostream>
using namespace std;
int main(){
int i = 0;
while (i != 10)
{
cout << "i:" << i++ <<endl;
}
}
do while语句
#include<iostream>
using namespace std;
int main(){
int i = 0;
do
{
cout << "i:" << i++ <<endl;
}
while(i != 10);
}
for循环语句
#include<iostream>
using namespace std;
int main(){
for(int i=0;i!=10;i++)
{
cout << "i:" << i <<endl;
}
}
嵌套循环语句
#include<iostream>
using namespace std;
int main(){
for(int i=0;i!=10;i++)
{
for(int i=0;i!=10;i++)
{
cout << "* ";
}
cout <<endl;
}
}
goto跳转语句
#include<iostream>
using namespace std;
int main(){
cout << "1、*********** "<<endl;
cout << "2、*********** "<<endl;
goto FLAG;
cout << "3、*********** "<<endl;
cout << "4、*********** "<<endl;
FLAG:
cout << "5、*********** "<<endl;
}